tsql add primary key column on existing table
I can add a new column to an existing table no problem, but i had problem making it an autoincrement int primary key. After some research I found the solution: "Identity" keyword:
if not exists(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'table1' AND COLUMN_NAME = 'ID')
begin
ALTER TABLE dbo.table1
add ID int identity not null
end
go
No comments:
Post a Comment