Re: identitycolumn as pk

From: Ivo Grootjes (IvoGrootjes_at_discussions.microsoft.com)
Date: 12/03/04


Date: Fri, 3 Dec 2004 06:29:08 -0800

GUIDS would solve the problem i guess but i see different problems with
GUIDS. We are using int(4) identity PK's because they're a good datatype for
sqlserver to index. I dont think this is the case with GUIDS or am i totally
wrong on this?

Are there any other solutions to this problem or do i have to generate
primary keys prior to inserting records?

"Ilya Margolin" wrote:

> Ivo,
>
> We had the same problem a while back and resolved it by switching to GUIDs
> in place of identity. It allowed us to copy data between databases/servers
> without breaking sweat.
>
> Ilya
>
> "Ivo Grootjes" <Ivo Grootjes@discussions.microsoft.com> wrote in message
> news:740F7730-0B08-460A-99BC-ACE525C95B88@microsoft.com...
> > Hi NG,
> >
> > This would be my first post on a newsgroup so bare with me :)
> >
> > I'm working on an existing application which uses a database with tables
> > which have identity columns as primarykeys. The webapplication needs new
> > functionality which requires 4 tables to be copied from one database to
> > another. The tables are related to eachother. For instance there's a
> chapter
> > table and a publication table. a chapter can contain 0..* publications.
> The
> > chapter table also has a relation toitself (allowing a hierarchical
> > structure). I'm receiving the data through a asp.net dataset which
> contains 4
> > datatables. What i want to do is insert the data in the new database
> through
> > 4 batch inserts but since i only know the primarykey after i've inserted a
> > record i can't do this.
> >
> > What i'm doing right now to overcome this issue is loop through the
> asp.net
> > datatables and insert the records one by one and store the generated keys
> so
> > i can use them for related records. Because the tables consist of tens of
> > thousands of records this is slow and not the preffered way of doing
> things.
> >
> > What would be a good solution to this. Should i generate a primarykey
> myself
> > outside of the database and change the database schema? I have the feeling
> > that that is the way to go but i'm not really sure. I think using identity
> > columns as primary keys is a commonly used technique so i bet there must
> be
> > other solutions to this problem. Changing the database schema ultimately
> is
> > an option but we prefer not to.
> >
> > Can anybody point out some tips, reading material, or anything else which
> > might help me to find a good solution to this problem?
> >
> > Thank in advance
>
>
>



Relevant Pages

  • RE: Cannot insert duplicate key row in object <tablename> with unique index
    ... | sure SQL server does not know this (I'm using guids extensively in this ... | similar to backing up a database into another database). ... | insert duplicate key row in object tblEntityDetailsEvent with unique index ...
    (microsoft.public.sqlserver.server)
  • Re: Trying to implent (Joe Celkos) Nested Sets, but need more data columns
    ... If GUIDs are used to identify a record ... They exist only in the current PHYSICAL STORAGE for the database. ... ROWID and other proprietary exposed physical locators are ... physical locator is not an identifier and it has no data integrity. ...
    (microsoft.public.sqlserver.programming)
  • Re: Use of UNIQUEIDENTIFIER vs IDENTITY for PK with VB.NET/SQL2000
    ... This topic has been done over many times in this newsgroup, ... perform a Google search on this newsgroup & you'll get lots of opinions, ... Another advantage of GUIDs ... orderdetail) at the application layer without round-trips to the database. ...
    (microsoft.public.sqlserver.programming)
  • Re: GUID question
    ... > that that will correspond to a database field on our database? ... Nothing prevents one from using GUIDs as surrogate primary keys. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Cannot insert duplicate key row in object <tablename> with unique index
    ... Basically I have 2 tables (tblEntitys and tblEntityDetailsEvent) (well more, ... sure SQL server does not know this (I'm using guids extensively in this ... similar to backing up a database into another database). ...
    (microsoft.public.sqlserver.server)