Article

Setting SQL Server ROWGUIDCOL property on [uniqueidentifier] (GUID) columns

I’ve been converted – I now use GUID (UNIQUEIDENTIFIERS) instead of INT for most database tables’ primary key.  If there is only going to be 100 or less rows, I don’t bother but most everything else I feel justifies the extra bytes of GUID. It ensures the key is unique which greatly simplifies merging data in the future.A nice feature about IDENTITY columns were there were properties that you could access that would identify which column is the IDENTITY one (only one may appear in a table).When using UNIQUEIDENTIFIERS instead, I wasn’t aware you could do the same.…or, if you don’t know the column name you can use a pseudocolumn $ROWDUID…This only works if a column’s ROWGUIDCOL property has been set. Just creating a UNIQUEIDENTIFIER colunn with a default of NEWID() or NEWSEQUIENTIALID() is not enough. I’ve been creating primary keys on UNIQUEIDENTIFIERS but not setting this property – but that is easily fixed:In the future, when I create tables with a GUUID as PK, i’ll include it in the create statement:Curiously, I’ve never noticed this column property before in SSMS:
column properties

column properties

Comments Closed.