|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Questions about the uniqidentifierHi,
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 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. "Arjen" <boah***@hotmail.com> wrote in message I'm using the newId() function inside CREATE statements for a new uniquenews:da0vm0$i9k$1@news6.zwoll1.ov.home.nl... Hi, 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 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 > > > > 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 > > > > > > > > > > > INLINE:
"Arjen" <boah***@hotmail.com> wrote in message Not impossible but highly unlikely.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? > Unique across every single computer in the world.> - Are the generated values unique for all table's? Or just for one column? > Not impossible but highly unlikely.> - If I delete some unique values, can the newId() function creates these > again? Show quote > > Thanks! > Arjen > > > |
|||||||||||||||||||||||