Search code examples
sql-serversql-server-2000uniqueidentifier

How to get the ROWGUIDCOL in SQL Server 2000 table?


How can i determine the name of the ROWGUIDCOL column in an SQL Server 2000 table?

i tried looking through syscolumns, e.g.:

SELECT *
FROM syscolumns
WHERE id = OBJECT_ID('Currencies')

But there is nothing there, or on the MSDN page that looks like rowguidcol.


Easy in SQL Server 2005

In SQL Server 2005 you just have to query sys.columns, e.g.:

SELECT *
FROM sys.columns
WHERE object_id = OBJECT_ID('Currencies')
AND is_rowguidcol = 1

Easy peasey.


Solution

  • You use COLUMNPROPERTY:

    SELECT COLUMNPROPERTY(id, name, 'IsRowGuidCol'), * FROM syscolumns ... ;
    

    In the format of the original question:

    SELECT *
    FROM syscolumns
    WHERE id = OBJECT_ID('dbo.Currencies')
    AND COLUMNPROPERTY(id, name, 'IsRowGuidCol') = 1;