获取某张表的主键

来源:互联网 发布:java快速开发平台框架 编辑:程序博客网 时间:2024/05/21 08:38
declare @tablename varchar(20)set @tablename = '需要查询的表名'select c.name as 字段名 from sysindexes i join sysindexkeys k on i.id = k.id and i.indid = k.indid join sysobjects o on i.id = o.id join syscolumns c on i.id=c.id and k.colid = c.colid join systypes t on c.xusertype=t.xusertype where o.xtype = 'U' and o.name=@tablename and exists(select 1 from sysobjects where xtype = 'PK' and parent_obj=i.id and name = i.name) order by o.name,k.colid

 
原创粉丝点击