Thursday, June 4, 2009

RowGUID

I learned something new today, regarding the RowGUID property in the SSMS Table Design view

In short, to use GUID as Primary Key (not recommended in general), set the column data type to uniqueidentifier, and default value of newid(), or better newsequentialid()

CREATE TABLE Product
ProductID UNIQUEIDENTIFIER PRIMARY KEY DEFAULT (newsequentialid()), 
ProductName VARCHAR(50), 
ListPrice money 
)    


Only set the RowGuid property to Yes if you are using Replication

Source
The setting of RowGuid=No is correct for a GUID pk. The RowGuid is used by SQL Server replication to uniquely identify rows across replicated databases (i.e. you have have two records with the same PK on different servers and when you replicate one database into the other, SQL Server will handle it). So, the RowGuid property of a column is independent from the primary key. Generally, when you use replication and a GUID pk, you can make them the same column.


Another good read - Can Sequential_GUID be the PK?

Wednesday, June 3, 2009

FREE e-book from Microsoft: Introducint Microsoft SQL Server 2008

You will need to sign in with your Passport/Live/Hotmail account
https://profile.microsoft.com/RegSysProfileCenter/wizard.aspx?wizid=2e29311d-516a-4817-bd65-b43e105cb666&lcid=1033

To save the book, press F8 for Toolbar and click the Save button.
Or go to the browser [File] menu and choose [Save As...]