if not Exists(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='PRIMARY KEY' AND TABLE_NAME='Users' and TABLE_SCHEMA='dbo') begin alter table Users add constraint Pk_Userid Primary key(Userid) end else begin --key exists end
end
if not Exists(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='PRIMARY KEY' AND TABLE_NAME='Users' and TABLE_SCHEMA='dbo') alter table Users add constraint Pk_Userid Primary key(Userid) else print 'key exists'
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)