GUIDs as keys - definition and use

  • Thread starter Thread starter Gene
  • Start date Start date
G

Gene

Hello,

I want to use GUIDs as keys for records in a number of tables for a database
I'm designing. The reason- I want to be able to "merge" records from
different site installations in the future and I don't want key conflicts.

Starting with the schema design (sqlserver)- what is the best "type" to pick
to hold the GUID?
I'm thinking varchar of length 36.

After I've designed the schema in SQLServer, I plan to use the server
explorer and create a dataset definition for use in .Net. - Any tips for
dealing with GUIDS with regard to the code the designer generates? i.e for
creating/modifying and deleting records?

Thanks in advance,
Gene
 
Gene said:
Hello,

I want to use GUIDs as keys for records in a number of tables for a database
I'm designing. The reason- I want to be able to "merge" records from
different site installations in the future and I don't want key conflicts.

This works well for this scenario, although some would argue a GUID is a bit
large. Note that this will eliminate the need to add a GUID (system will do
for you) if you choose replication, which sounds like your goal.
Starting with the schema design (sqlserver)- what is the best "type" to pick
to hold the GUID?
I'm thinking varchar of length 36.

uniqueidentifier is a GUID type. Also, you can set a particular column as a
Row GUID and have it automatically get set to newid(). This is much like an
Identity column for a numeric key.
After I've designed the schema in SQLServer, I plan to use the server
explorer and create a dataset definition for use in .Net. - Any tips for
dealing with GUIDS with regard to the code the designer generates? i.e for
creating/modifying and deleting records?

Custom build your update to allow SQL Server to create the GUID for you when
you input the records. I would suggest that for most applications anyway, as
I find the default methodology to be a bit lacking. As it is rather easy to
attach sprocs to CRUD with a DataAdapter, you should not have a lot of
difficulty after you make the mental shift away from the drag-and-drop
mentality MS is pushing. You can still drag controls on a page, but you will
have to jump into the code MS tells you not to touch and change the commands
on the DA.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top