SQL SERVER – Identity Column is Difficult to Remove

The IDENTITY property is difficult to remove through a column alteration because SQL Server doesn’t support that operation. Existing values need protection.

Original vessels and supporting fittings remain preserved beside a replacement drawer.

  1. Rebuild the table with an ordinary column and copy the existing values, preserving the complete table contract.
  2. Where suitable, add an ordinary replacement column, populate it, reconstruct its dependencies, then deliberately retire and rename columns.
SELECT s.name AS SchemaName,t.name AS TableName,c.name AS ColumnName,
       c.seed_value,c.increment_value,c.last_value
FROM sys.identity_columns c JOIN sys.tables t ON t.object_id=c.object_id
JOIN sys.schemas s ON s.schema_id=t.schema_id ORDER BY s.name,t.name;

My original second option mistakenly recreated an identity column. The replacement must be non-identity. Review keys, indexes, defaults, triggers, permissions, replication and application references for either route.

Plan consistency with active writers and preserve a recoverable backup. Validate counts, keys and values on a copy. Dropping columns or swapping tables without dependency work can break consumers or lose metadata.

The inventory identifies identity columns without migrating them. The related articles and negative-identity video explain property and value behavior. Stored values and automatic generation are separate concerns.

Related reading

An identity migration is not a simple rename, it is a data-and-dependency change that needs validation.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Identity, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Unlocking User Without Changing Password
Next Post
MS Access – Count Distinct Values

Related Posts

1 Comment. Leave new

  • Imran Mohammed
    June 16, 2021 9:14 pm

    Microsoft made developer’s lazy with auto increment seed (Identity Columns). But it comes with some disadvantages. Sequences are good alternatives to Identity columns but does require additional efforts.

    We are so used to Identity Columns, especially in DW world, its impossible to picture a traditional DW without Identity columns for surrogate keys. But I now see many developers moving away from the choice of Identity columns for surrogate keys.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.