【转】【SQL Server】查询数据表主键及主键类型

详细内容查看:https://blog.csdn.net/weixin_43347659/article/details/120829241

查询某个表的主键名称:

select c.name
from sys.indexes i 
    join sys.index_columns ic on i.object_id = ic.object_id and i.index_id = ic.index_id
    join sys.columns c on ic.object_id = c.object_id and ic.column_id = c.column_id
where i.is_primary_key = 1 
    and i.object_id = object_id('u_store_i')

 

posted @ 2022-08-23 17:11  竹楼风雨声  阅读(125)  评论(0编辑  收藏  举报