Trying to use a composite unique index instead of a composite unique identifier - sql-server

I am evaluating outsystems and am trying to write a PoC List/CRUD app based on a legacy database table (the structure of which cannot be changed) which does not have a primary key but instead has two text fields that together constitute a unique index. The database is SQL Server 2014.
The table is successfully added in Integration Studio using "Connect to External table or view".
Then when I open the TestApp in Service Studio and go to the data tab I see the entity there, but it's not usable because it has no identifier defined. I have read some online info that I can double click on the entity and go to the Indexes tab. Here I normally would expect to see the index already defined in the database but it's not there. I also expect to the the New and Delete buttons to be enabled so I can create and delete indexes but New is disabled.
Am I correct to assume that OutSystems should have already "seen" the existing composite unique index? If so, am I correct to assume that this index would have sufficed to create a pseudo/virtual identifier for the entity, whereby making the entity system happy for CRUD and List operations? And also why is the New button not enabled for me to even manually create the index?
Can someone help me please in the correct direction?
Thanks

The OutSystems platform only supports single primary keys, so you have to create the CRUD operations by hand.
For external entities, index information is not fetched from the database, and the reason you can't create the index is because OutSystems doesn't control the metadata (i.e. you can't create indexes, create/modify columns, etc).

Related

Why does view become read only when linked to Access?

In SQL Server Management Studio, I created both indexed and regular (non indexed) views. When I updated the data, the base table's data was changed as well. However, when I link my views to Access using VBA or using Access GUI linked tables I need to specify a index. If I do not do so the view will be read only.
Why is non indexed view read only in Access but not in SQL?
I personally found it very difficult to digest the accepted answer and work out what the problem was and how to resolve it.
Why aren't linked views editable?
Essentially, SQL Server views do not have a Primary Key (PK) and, therefore, are considered read-only (non-updateable) by MS Access because MS Access requires a unique column to use for updates.
How to edit the data in a linked view
A UNIQUE INDEX must be created in MS Access after the view has been linked.
For example, if the table is called dbo_table and the PK column in SQL is called id, create a new query and paste the following into it:
CREATE UNIQUE INDEX myPK ON dbo_table (id ASC)
The word myPK is the name of the index (this can be renamed if needed). Execute the query.
The linked view will now be updateable.
The reference documentation for MS Access CREATE INDEX is available here.
Well, first of all, when you use the Access GUI to link to a table, it NEVER prompts you for an index, it prompt you for the primary key. So let’s get that crazy and silly misinformation corrected like REAL fast, shall we?
When you link to a SQL server view, you get this prompt:
That above prompt is not asking you for a index.
The reason why access does this is because it needs a PK to update a linked table, or a linked view.
PROBLEM:
SQL server does not have a PK defined for a view. And SQL server DOES NOT LET YOU SPECIFY a PK for a view. If SQL server had some way to define a PK for a view, then Access could use that information to grab the PK.
However, since views don’t have a PK on sql server, then when linking to such Views YOU THE HUMAN have to choose a PK.
Access linked tables are read only without a PK.
Access linked views are read only without a PK.
However, sql server views do NOT have a PK defined.
Again:
SQL server views do NOT have a PK defined.
If you create the linked view with VBA code, then no GUI prompt appears asking you for the PK. You can tell Access which column is to be “assumed” as the PK by executing a local create index command. This command DOES NOT ACTUALLY CREATE a index. It does not create one server side, and it does NOT create a actual working index on the access client side.
All the create index command does is tell access what PK column to use. So you not actually creating a index in this case.
Again:
SQL server views do NOT have a PK defined.
If SQL server allowed one to create or set a PK for a view, then Access could simply use that information and know what PK to use, and then set it for you.
However (and again)
SQL server does not have a PK defined for a view.
However for the access client to update a linked table, it needs a PK. When linking to a table, Access can simple ask SQL server what column is the PK. However, you cannot ask SQL server
“what is the primary key” of a view.
(however, you can for a table).
So you not creating a index in Access (it does nothing since a index on the client side of access with a linked table, or a linked view is NOT a working index and does NOTHING!!! (except provide a place to tell access what colum is the PK). It is NOT working index nor is it even a real index.
The existence of an index in Access for linked tables/views does not actually create a working index – only that some “extra” information such as if a PK exists in the table is stored when you “create” that index.
Again: Access does not create indexs for linked table. When you execute create index on a linked table A INDEX IS NOT CREATED IN THIS CASE. ONLY INFORMATION ABOUT THE TABLE OR VIEW IS STORED LOCAL IN ACCESS.
Again: you not creating a index.
Again:
If sql server had a feature or option to define a PK for a view, then no doubt Access would also use that information. However, views in sql server don’t have a defined PK, and thus Access can’t use the PK, and if access can’t find a PK, then it assumes the table is read only.
The SQL management studio can often update tables without a PK, but Access has to use ODBC to connect to sql server, and ODBC has FAR LESS features then SSMS when connecting to a database.

Is there a GUID per MySQL database?

I am looking for a way to get a unique ID per database itself. The idea is to exchange objects between different installations of my application. Therefore I have unique IDs for all objects within a single database, but in order to exchange these objects to other databases with the same schema, I introduced a composite ID consisting of a primary and a secondary ID, where the primary is unique within a single database and the secondary should be unique across multiple databases with the same schema.
Does somebody knows a decentralized solution for this issue?
Using a global unique identifier for each row solves the problem. Java itself provides a UUID generator, but there are more (better) third-party generators as well.

Updating Records In a Second Table Using Foreign Keys

I have a database in which two tables have a 1:1 relationship using foreign keys. Table one is called Manifest and table two is called Inventory. When an inventory record is added using the application this is built for it uses a foreign key to reference the matching record in the manifest table. In addition, this causes an update to a column in the manifest table for the matching record called Received (datatype: BIT) to 1. This is used for reconciliation and reporting purposes.
Now here is where it gets tricky: This database is synchronized to a server database using Sync Framework in a client-server relationship. The Manifest table is synchronized in one direction from server to client, and the Inventory table is synchronized from client to server. Because of this the "received" column in the Manifest table is not always updated accurately on the server-side after a sync.
I was thinking of creating a stored procedure to perform this update, but I'm a bit rusty on my SQL (and T-SQL). The SP I was thinking of using would use a CURSOR to locate any records in the inventory table where the foreign key is NOT NULL (this is allowed due to exceptions where we receive something that was not in the manifest). The cursor would then allow me to iterate though all the records to locate the matching record in the manifest table and update the "received" column. I know that this cannot be the best way to perform this update. Can anyone suggest another way of doing this that would be faster and use less resources? Examples would be appreciated =)

How do you create a composite key for a View in SQL Server 2008?

I need to create a composite key for a view in SQL Server 2008 because I cannot import a view into entity framework without a primary key defined and since Views don't have primary keys I have to create. Right now I am getting this error when I try to import the View into EF.
The table/view 'FanDB.dbo.Quick_View' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.
I have been able to add the View to EF before but my boss deleted our DB and so I am recreating the DB from scratch. I have just forgotten how I did it:( Thanks for your help, feel free to ask any questions I will be checking back as often as I can and if I figure it out I will post the solution because all the questions on stack overflow either say to edit the XML file(can't do this because I can't add it to the .edmx) or add a primary key column which I can't do because it is a quick view.
You could recreate the view as a table, add a primary key, import it into EF, and then drop table and reinstate the view. This will get your table into EF, but then you have to be careful whenever you update the model again in the future.
Alternatively, you could create a model db, with all the same object names as your actual db, but with views created as tables. At design time, use the model db, and at run time, use the actual db. So long as the view is updateable, the EF runtime won't care that it's actually a view, and not a table.
If you are feeling compulsive, and have a lot a tables, it wouldn't be too hard to auto-magically generate the model db from the actual db.

Vs2010 Data Generation Plan fails with "Data generation failed because of the following exception: Column "xyz" does not allow DBNull.Value"

I'm fairly new to Vs Data capabilities, and this is my first data generation plan. I have implemented a database using a Vs2010 database project, and used it to deploy to a sql server express 2008 database. All the tables use identity columns as their primary keys, and they're related to one another with foreign keys.
I set up a data generation plan, but when I try to generate data with it, the tables are simply populated in alphabetical order, which is of course going to fail. The only tables that populate correctly are the lookup tables and other sorts of independent entities with no FK constraints. The rest are skipped after the first table fails.
Supposedly the generation plan determines the population order based on FK dependencies. What happened?
edit: someone with the rep for it should make a visual-studio-data-tools tag, since DBPro is no longer (nor really ever was) a product name.
So apparently according to this thread the data generation plan blows up when you have a table containing only a primary key and no other columns. It turns out that one of my independent entities, whose only purpose is to serve as a joinder to one of my other tables, fit this description. After adding a harmless Description column, I was able to proceed fixing other problems until the generation plan completed successfully.

Resources