当前位置: 代码迷 >> Sql Server >> 请教怎么用sql语句查看一个表的主键,请详细说一下,多谢
  详细解决方案

请教怎么用sql语句查看一个表的主键,请详细说一下,多谢

热度:7   发布时间:2016-04-27 16:21:01.0
请问如何用sql语句查看一个表的主键,请详细说一下,谢谢
如题

------解决方案--------------------
select * from (
select b.name as tblname ,a.name as colname,
主键=case when exists(SELECT 1 FROM sysobjects where xtype= 'PK ' and name in (
SELECT name FROM sysindexes WHERE indid in(
SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
))) then '√ ' else ' ' end
from syscolumns a ,sysobjects b
where a.id=b.id and b.xtype= 'u ') aa
where 主键!= ' '
  相关解决方案