Home All Groups Group Topic Archive Search About

Questions about the uniqidentifier

Author
30 Jun 2005 2:30 PM
Arjen
Hi,

I'm using the newId() function inside CREATE statements for a new unique
value.

- Do I need to set the "Is identity" property to "yes"?

- What's happen when the newId() function creates a value that already
exists? Or is this impossible?

- Are the generated values unique for all table's? Or just for one column?

- If I delete some unique values, can the newId() function creates these
again?

Thanks!
Arjen

Author
30 Jun 2005 2:41 PM
Narayana Vyas Kondreddi
You should not be setting identity property for unique identifier columns.
See the page titled "Using uniqueidentifier Data" in SQL Server 2000 Books
Online. This answers the rest of your questions.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


"Arjen" <boah***@hotmail.com> wrote in message
news:da0vm0$i9k$1@news6.zwoll1.ov.home.nl...
Hi,

I'm using the newId() function inside CREATE statements for a new unique
value.

- Do I need to set the "Is identity" property to "yes"?

- What's happen when the newId() function creates a value that already
exists? Or is this impossible?

- Are the generated values unique for all table's? Or just for one column?

- If I delete some unique values, can the newId() function creates these
again?

Thanks!
Arjen
Author
30 Jun 2005 3:00 PM
Arjen
The string representation of a GUID is URL-friendly, so I could use the
uniqueidentifier in my URL without HTML-encoding it.

The disadvantages is that the values are long. Indexes built using
uniqueidentifier keys may be relatively slower than implementing the indexes
using an int key.

But I don't want to use a "simple" int. Where users can guess the URL by
typing in some numbers.

Do you know some good alternatives for generating obscure values (numbers
only?)?

Thanks!




Show quote
"Narayana Vyas Kondreddi" <answer***@hotmail.com> schreef in bericht
news:%23pOmSHYfFHA.1048@tk2msftngp13.phx.gbl...
> You should not be setting identity property for unique identifier columns.
> See the page titled "Using uniqueidentifier Data" in SQL Server 2000 Books
> Online. This answers the rest of your questions.
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/
>
>
> "Arjen" <boah***@hotmail.com> wrote in message
> news:da0vm0$i9k$1@news6.zwoll1.ov.home.nl...
> Hi,
>
> I'm using the newId() function inside CREATE statements for a new unique
> value.
>
> - Do I need to set the "Is identity" property to "yes"?
>
> - What's happen when the newId() function creates a value that already
> exists? Or is this impossible?
>
> - Are the generated values unique for all table's? Or just for one column?
>
> - If I delete some unique values, can the newId() function creates these
> again?
>
> Thanks!
> Arjen
>
>
>
>
Author
30 Jun 2005 4:33 PM
KH
You have to have quite a lot of data to notice any difference in performance
between using a guid vs. an int. Heck for that matter an int is bigger than a
smallint and so would theorthetically perform worse. Don't forget that you
don't have to start with "1" - starting a smallint identity field at -32768
gets you 65,535 unique ids.

The real "problem" with using a guid as a PK (or other index) is that they
aren't generated in numeric order, so when you insert a new record with a
guid PK it will probably insert somewhere in the middle of the index, causing
more page splits than an incrementing integer value.

To disguise your integer ids you might convert them to their binary
representation. Some people will see what you're up to, but not most:

DECLARE @i INT
SELECT @i = 763
SELECT CONVERT(BINARY(4), @i)


Show quote
"Arjen" wrote:

> The string representation of a GUID is URL-friendly, so I could use the
> uniqueidentifier in my URL without HTML-encoding it.
>
> The disadvantages is that the values are long. Indexes built using
> uniqueidentifier keys may be relatively slower than implementing the indexes
> using an int key.
>
> But I don't want to use a "simple" int. Where users can guess the URL by
> typing in some numbers.
>
> Do you know some good alternatives for generating obscure values (numbers
> only?)?
>
> Thanks!
>
>
>
>
> "Narayana Vyas Kondreddi" <answer***@hotmail.com> schreef in bericht
> news:%23pOmSHYfFHA.1048@tk2msftngp13.phx.gbl...
> > You should not be setting identity property for unique identifier columns.
> > See the page titled "Using uniqueidentifier Data" in SQL Server 2000 Books
> > Online. This answers the rest of your questions.
> > --
> > HTH,
> > Vyas, MVP (SQL Server)
> > SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/
> >
> >
> > "Arjen" <boah***@hotmail.com> wrote in message
> > news:da0vm0$i9k$1@news6.zwoll1.ov.home.nl...
> > Hi,
> >
> > I'm using the newId() function inside CREATE statements for a new unique
> > value.
> >
> > - Do I need to set the "Is identity" property to "yes"?
> >
> > - What's happen when the newId() function creates a value that already
> > exists? Or is this impossible?
> >
> > - Are the generated values unique for all table's? Or just for one column?
> >
> > - If I delete some unique values, can the newId() function creates these
> > again?
> >
> > Thanks!
> > Arjen
> >
> >
> >
> >
>
>
>
Author
30 Jun 2005 2:49 PM
Raymond D'Anjou
INLINE:

"Arjen" <boah***@hotmail.com> wrote in message
news:da0vm0$i9k$1@news6.zwoll1.ov.home.nl...
> Hi,
>
> I'm using the newId() function inside CREATE statements for a new unique
> value.
>
> - Do I need to set the "Is identity" property to "yes"?
No.

>
> - What's happen when the newId() function creates a value that already
> exists? Or is this impossible?
Not impossible but highly unlikely.

>
> - Are the generated values unique for all table's? Or just for one column?
Unique across every single computer in the world.

>
> - If I delete some unique values, can the newId() function creates these
> again?
Not impossible but highly unlikely.

Show quote
>
> Thanks!
> Arjen
>
>
>

AddThis Social Bookmark Button