How to remove identity on primary key column in SQL Server 2016?
Asked
Active
Viewed 1.3k times
-2
-
6Possible duplicate of [Remove Identity from a column in a table](https://stackoverflow.com/questions/8230257/remove-identity-from-a-column-in-a-table) – TZHX May 22 '18 at 15:57
2 Answers
3
Create a new column, copy the data, drop original column
alter table yourtable
add newcolumn int
update yourtable
set newcolumn=oldcolumn
alter table yourtable
drop column oldcolumn

Daniel Marcus
- 2,686
- 1
- 7
- 13
-
-
Remove all the foreign key constraints and then put them back when you are done - see the link above in the comments section for more detail – Daniel Marcus May 22 '18 at 16:03
-
-
How to turn off the identity on column and turn on the auto increament as column is referred as foreign key on other table? – Naga May 22 '18 at 16:50
-
Foreign key on the other table is the value that points to the primary key of another table - remove all foreign keys pointing the your identity column and then recreate them pointing to the new column when you are done – Daniel Marcus May 22 '18 at 16:51
-
-
-4
you can't remove Identity on a primary key column. It is by default gets created when you choose a column as Primary. You need to do alternatives which I don't recommend on project tables.
1) Drop the primary key with cascade option (You will lose the links to child tables)
2)
- You need to create another column with a different name in the same table.
- copy that data into newly created column
- Delete the primary key column.
this will leave orphan records in child tables that are being referenced.

Lokesh Kamalay
- 1
- 1
-
2This is incorrect, SQL Server primary key columns are not identity fields by default. – TabbyCool Sep 04 '18 at 11:24