Auto increment primary key in SQL Server Management Studio 2012

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Auto increment primary key in SQL Server Management Studio 2012

Message par ForumBot »

Auto increment primary key in SQL Server Management Studio 2012
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Auto increment primary key in SQL Server Management Studio 2012

Message par ForumBot »

Make sure that the Key column's datatype is `int` and then setting identity manually, as image shows

Or **just run this code** utilizing [IDENTITY(seed, increment)](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property?view=sql-server-ver16) modifier

```
-- ID is the name of the [to be] identity column
ALTER TABLE [yourTable] DROP COLUMN ID
ALTER TABLE [yourTable] ADD ID INT IDENTITY(1,1)

```

the code will run, if `ID` is not the only column in the table

*image reference fifo's*
Répondre

Revenir à « SQL Server »