Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 GUID as primary key

Author  Topic 

opi
Starting Member

29 Posts

Posted - 2008-03-13 : 06:49:06
I have a table profiles and a table resumes.
The id's are currently int indentity fields.
I was thinking of using a GUID as ID.

Why would i do this ?

In my webapplication I have i.e. this page
DeleteProfile.aspx?profileId=1

I don't want to give the user the ability to change this to f.e.
DeleteProfile.aspx?profileId=3

A user will almost possibly never guess a certain GUID, right ?

Is this a good idea, or not ?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 06:53:03
A bad idea.
A guid is the worst datatype to index, due to it's randomness.
Keep int columns as identity, but make newid() for new columns as alternative.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

opi
Starting Member

29 Posts

Posted - 2008-03-13 : 06:54:54
quote:
Originally posted by Peso

but make newid() for new columns as alternative.



E 12°55'05.25"
N 56°04'39.16"




Can you elaborate on this please ?
New to MS SQL Server 2005, sorry
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-03-13 : 07:34:25
I've been using GUIDs as pkeys for years and never had any performance issues. I've even seen some arguments that they are faster because they are distributed randomly.
Go ahead and use the GUIDs.

e4 d5 xd5 Nf6
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 08:21:08
For one thing, a GUID is 16 bytes, which means you can cram in about 500 of them in one page.
If you use INT, you can cram in about 2000 of them in one page.

This means for a performance viewpoint, you only need 25% of index size to maintain, store and search through using INT in favor of GUID.

Paul Randal wrote here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53085&whichpage=2 (see #10).


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

opi
Starting Member

29 Posts

Posted - 2008-03-13 : 08:23:34
Peso,

What did you exactly mean with :
but make newid() for new columns as alternative
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 08:27:02
I meant you could keep the int as identity column and use that to join other columns.
In same table add a new UNIQUEIDENTIFIER column which has NEWID() as default value.

But in your case (written in original post) you really should have some kind of security mechanism so that the only two persons able to delete a profile is

a) myself
b) system admin



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -