SQL常用语句

--查询表主键
EXEC sp_pkeys @table_name='Plat_CommAttrSelect'

--删除表主键
Declare @Pk varChar(100);
Select @Pk=Name from sysobjects where Parent_Obj=OBJECT_ID('Plat_CommAttrSelect') and xtype='PK';
if @Pk is not null
exec('Alter table Plat_CommAttrSelect Drop '+ @Pk)

--添加表主键
alter table Plat_CommAttrSelect add constraint Plat_CommAttrSelect_PK primary key(ID)