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
获取某张表的主键
最新推荐文章于 2023-09-10 23:32:05 发布