How do I add the IDENTITY property to existing SQL Azure table? - sql-server

I have created a couple of tables in SQL Azure and forgot to mark the primary keys as identity columns. There is no data in the tables yet, but the check box marked Is Identity is disabled.
How do I make an existing primary key an identity column in SQL Azure?

You create a new table. You can't change the IDENTITY property in a regular SQL Server instance either - well, depending on your settings, SSMS might let you, but it doesn't tell you what it actually does behind the scenes - drops the table and re-creates it. Don't believe me? Script it out or profile it.

Related

How to copy a SQL table to another server with index and keys?

I am trying to copy 2 tables from one server to another with the primary key, data and index.
Method 1:
I have tried with import/export wizard and exported data, also edited the script to have primary key and identity and checked the insert identity checkbox before execution.
Method 2:
Generated script for those 2 tables with Types of data to script - Schema and data and Script Indexes - True
But in both of these method, i am losing the identity functionality in the new table. When I do a right click on the new table and select Design option, the Identity Specification is stated as NO but in the old table it is staed as YES.
Is there any other method to copy a table with this identity functionality?
Obviously there is a bug in Microsoft SSMS. With your method 1 SSMS 2016 still executes the standard CREATE TABLE query in the background, although you edit it in the wizard. My recommendation is that you download and install the latest SSMS version. Here is the link to it. After that you can use your method 1 without problems and it will work without problems.

Oracle ADF Insert operation set SQL Server database to use database auto increment PK

I am making a simple CRUD application using Oracle ADF with SQL Server database.
My problem is that when inserting a new record into SQL Server table, I get an error on the primary key. My table has a primary key as Auto_Increment, but ADF is having problems to respect the database to do its own Auto_increment how do you go about this. I am sure there is a simple solution that works but I cant find one.
Regards
Xavier

Change Primary keys from int to guid in existing database

I have taken over a project with an existing SQL server installation. The client wants to move everything to the azure SQL and make several on premises databases sync to azure.
The PK's in the tables are int's and for the Azure datasync to work PK's needs to be guid's. the database consists of several related tables.
My question is therefore. What is the best way to change the PK's to guids and at the same time update the FK's accordingly in existing tables.
The process as far as I see it:
1. Create new guid column
2. fill it with ID's.
3. change the PK to the guid column
4. update data to new guids in the FK tables.
Is there an easy scriptable way to make this magically happen?
No there is nothing built into SQL Server that makes this any easier than the process you described already.

SQL Server 2008 won't let me add foreign keys

I've been using SQL Server for years, so I'm not a noob. I've recently been having problems where I can't add a foreign key to certain tables in my database using SQL Management Studio and SQL Server 2008 Express. The table I'm trying to reference is there and it has a primary key (with the primary key constraint created), but it doesn't show up in the list of tables that I can choose from when I'm trying to add the FK.
If I try and add the FK through plain old T-SQL, the query succeeds, but if I view the new FK using the UI, the primary key table dropdown is empty. The FK is there and it actually does work if I try to insert some data that would violate the constraint.
Anyone know why this would be happening?
This sounds like a tool issue (SSMS), not an engine issue
Thoughts:
close/reopen SSMS (caching?)
patched to same version as server install?
different schema etc?
Edit, after comment and it's SSMS caching:
You can also right-click on the table node and refresh so SSMS updates the cache. This problem goes back to SQL Enterprise Manager and SQL 2000. No known fix after 10 years...

When should you enable the RowGuid column property in SQL Server 2005?

The MSDN documenation states:
Indicates whether SQL Server uses the column as a ROWGUID. You can set this value to Yes only for a unique identity column.
This doesn't tell me why I would have this enabled or disabled.
Setting the column as ROWGUID tells SQL Server that that row will be used as a GUID. By default SQL Server will set the default value of the row to NewID() which will generate a GUID.
So, you would use it when you want to use GUIDs, which are globally unique. This makes them useful for replicating and merging databases since you know that no two rows will ever (theoretically) have the same id.

Resources