sqlserver怎么通过objectID来查询表名字
发布网友
发布时间:2022-04-30 16:25
我来回答
共3个回答
热心网友
时间:2022-04-11 20:21
主键约束
SELECT
tab.name AS [表名],
idx.name AS [主键名称],
col.name AS [主键列名]
FROM
sys.indexes idx
JOIN sys.index_columns idxCol
ON (idx.object_id = idxCol.object_id
AND idx.index_id = idxCol.index_id
AND idx.is_primary_key = 1)
JOIN sys.tables tab
ON (idx.object_id = tab.object_id)
JOIN sys.columns col
ON (idx.object_id = col.object_id
AND idxCol.column_id = col.column_id);
唯一约束
SELECT
tab.name AS [表名],
idx.name AS [约束名称],
col.name AS [约束列名]
FROM
sys.indexes idx
JOIN sys.index_columns idxCol
ON (idx.object_id = idxCol.object_id
AND idx.index_id = idxCol.index_id
AND idx.is_unique_constraint = 1)
JOIN sys.tables tab
ON (idx.object_id = tab.object_id)
JOIN sys.columns col
ON (idx.object_id = col.object_id
AND idxCol.column_id = col.column_id);
热心网友
时间:2022-04-11 21:39
请采用以下sql脚本
select object_name(21575115) ----21575115表Id
sql_object_name函数用法
sql脚本中,有一个系统函数,object_name可以精准的获取指定ID所对应的对象名称。
请采纳!
热心网友
时间:2022-04-11 23:13
select objectID from 表名