Sql sever 获得一个表的主键
方法一、Execute sp_pkeys 'pdj'
方法二、
Select
col_name(object_id('pdj'),colid) '主键字段'
From sysobjects as o
Inner Join sysindexes as i On i.name=o.name
Inner Join sysindexkeys as k On k.indid=i.indid
Where
o.xtype = 'PK' and parent_obj=object_id('pdj') and k.id=object_id('pdj')
说明:获得所有索引和类型
Select
i.name,col_name(k.id,colid),o.xtype
From sysobjects as o
Inner Join sysindexes as i On i.name=o.name
Inner Join sysindexkeys as k On k.indid=i.indid
Where parent_obj=k.id