我需要编写一个查询,该查询将返回具有数据类型 uniqueidentifier 的主键列的所有表名称。
任何人都可以帮助我吗?
最佳答案
使用 SQL Server object catalog views :
select
IndexName = i.name
, SchemaName = schema_Name(t.schema_id)
, TableName = t.Name
, ColumnName = c.Name
, TypeName = type_name(c.user_type_id)
from sys.tables t
inner join sys.indexes as i on
t.object_id = i.object_id
and i.is_primary_key = 1
inner join sys.index_columns as ic on
i.object_id = ic.object_id
and i.index_id = ic.index_id
inner join sys.columns as c on
c.column_id = ic.column_id
and c.object_id = ic.object_id
and type_name(c.user_type_id) = 'uniqueidentifier'
rextester链接:http://rextester.com/SAL18997
关于sql-server - 获取 SQL Server 中所有具有数据类型 uniqueidentifier 的主键的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41957690/