是否有我可以加入的系统表,因此我可以查询以查找标记为ROWGUIDCOL的列的所有表?
谢谢!
答案 0 :(得分:3)
您可以使用此SQL查询来实现目标。 Objects.Type = 'U'
是用户表。
SELECT O.name AS table_name,
C.name AS column_name
FROM sys.objects AS O
JOIN sys.columns AS C ON C.object_id = O.object_id
WHERE o.type = 'U'
AND C.is_rowguidcol = 1
答案 1 :(得分:2)
您可以sys.columns
使用COLUMNPROPERTY
:
SELECT DISTINCT OBJECT_NAME(object_id) AS tab_name
FROM sys.columns
WHERE COLUMNPROPERTY(object_id, name, 'IsRowGuidCol') = 1
的 SqlFiddleDemo
强>
CREATE TABLE MyTable(ID UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID());
CREATE TABLE MyTable2(ID UNIQUEIDENTIFIER ROWGUIDCOL PRIMARY KEY
DEFAULT NEWSEQUENTIALID());
输出:
╔══════════╗
║ tab_name ║
╠══════════╣
║ MyTable2 ║
╚══════════╝
答案 2 :(得分:0)
你可以这样使用COLUMNPROPERTY()
:
SELECT COLUMNPROPERTY(OBJECT_ID(C.TABLE_NAME), c.COLUMN_NAME, 'IsRowGuidCol') AS IsRowGuidCol
,* 来自INFORMATION_SCHEMA.COLUMNS作为C. COLUMNPROPERTY(OBJECT_ID(C.TABLE_NAME),c.COLUMN_NAME,'IsRowGuidCol')= 1