Skip to content
Advertisement

Find all tables that have ROWGUIDCOL

IS there a system table I can join to so I can query to find all tables with a column flagged as ROWGUIDCOL?

thanks!

Advertisement

Answer

You could utilize sys.columns with 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());

Output:

╔══════════╗
║ tab_name ║
╠══════════╣
║ MyTable2 ║
╚══════════╝
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement