Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am in the process of redesigning an SQL server database for an ASP.Net application. The designer of the original database used the uniqueidentifier type for primary keys on each table.

 

A GUID seems a little complicated for the IDs on these. I'm used to memorizing a simple number when I cross-reference related tables. Plus I have to include code in my application to generate the GUID when I insert a new record. I'm thinking of switching to an auto-incrementing ID for the new database.

 

Before I do, I'd like to know what the advantages are to using a GUID instead of a number for a primary key.

  • Administrators
Posted

GUIDs are guarenteed unique across systems so if you are likely to be replicating data around then these are one way of preventing clashes. This uniqueness will also come in handy if you ever have to import data or consolodate from multiple sources.

 

Downsides are they are slightly slower (but then just about everything is slower than an int anyway) and take up slightly more storage space. The other main downside is there is no easy way to retrieve a newely generated guid for a table entry (i.e. no straight match for the @@IDENTITY function), however if you are doing all updates via stored procs (you should) then it is an easy matter to generate the GUID, insert it and then report it back via an OUTPUT parameter or similar.

 

All in all if the system is already working I would be reluctant to switch from GUIDs to integers as there really aren't any benefits to be gained that would justify the hassle of the conversion.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
All in all if the system is already working I would be reluctant to switch from GUIDs to integers as there really aren't any benefits to be gained that would justify the hassle of the conversion.

 

Fortunately, I'm rebuilding both the database and the ASP application from scratch, so I don't have to go through the trouble of converting the existing system.

Posted
the benifit of guids is they are fastr in that you can generate them yourself and NOT depend on the database. you have it at insert time so you can use ot to insert into child tables. I highly recommend guids over identity ints

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...