Modify an existing column for identification

Possible duplicate:
How to change a non-identity program column by one?

I want to set the column as an identifier since I already created this column in the table.

What syntax do I need? ALTER ...?

+3
source share
4 answers

You cannot add an identifier to an existing column; you must create a new column.

+2
source

With table test

create table Test(ID int)

You can do it

exec sp_rename 'dbo.Test', 'tmp_Test', 'OBJECT'
go

create table dbo.Test(
  ID int not null identity
)
go

set identity_insert dbo.Test on
go

insert into dbo.Test(ID) select ID from dbo.tmp_Test
go

set identity_insert dbo.Test off
go

drop table dbo.tmp_Test
go
+1
source

SMSS → . → - > - > .

0

SQL, :

ALTER TABLE <TableName> ADD CONSTRAINT PK_<TableName> PRIMARYKEY(Column)
-4

Source: https://habr.com/ru/post/1795726/


All Articles