MS SQL Server Row GUID Column

早过忘川 提交于 2019-12-18 10:49:13

问题


I apologize for asking what seems like a tired question, but no forum response or documentation I've read seems to provide an adequate answer.

What is the purpose of the Row GUID Column property in MS SQL Server 2008?

Let me extend on that. I've seen "Don't use GUID as the PK" repeated as the answer for this question, which seems to be completely unrelated to me. If I set Row GUID Column is it forcing that GUID column to be the primary key or something?

To rephrase my original question: If I have a GUID column in my table that does not play any role in indexing, do I stand to gain anything from setting that GUID column as the Row GUID Column?


回答1:


It enables you to use the $ROWGUID variable instead of the column name. It's used mostly for merge replication. It doesn't force the GUID column for PK, you can only declare PKs explicitly. The answer to your last question is no, unless you plan on implementing Merge Replication.




回答2:


The ROWGUIDCOLUMN is used primarily in replication scenarios where you need to combine the contents of several satelite databases' tables into one central DB.

Adding a ROWGUIDCOLUMN to the tables being replicated ensures that the replication engine can use the ROWGUIDCOLUMN field to differentiate between records with the same primary key values.

Because this is a feature primarily used to ensure smooth replication, you should avoid using this column as your primary key. Your primary key should be a logical business entity that is under your control and which doesn't affect the operational characteristics of specific features of your chosen DB engine.




回答3:


RowGUID column is used for replication. It allows the replication engine to merge correctly. When replication is enabled this column will be added to tables that do not already have a RowGUID column.

You will not gain anything by using it unless you are planning to implement replication. It is equivalent to setting newsequentialid() as the default value for a column.




回答4:


It's not forcing it to be the primary key, the property merely determines if the field will be automatically updated. IF you want to create the GUID in the application and send it in, set this property to false, otherwise set it to true and let the database create it automatically. If the field is the clustered index make sure the default value is NEWSEQUENTIALID().




回答5:


No it doesn't force it as the PK. It does mean you can't create a second uniqueidentifier and specify that as the Row GUID Column



来源:https://stackoverflow.com/questions/4443036/ms-sql-server-row-guid-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!