Re: How to determine GUID of newly-inserted record?



You may also generate the GUIDs yourself and remove the IsRowGuid property
from the columns. This way, you would know the GUID value before inserting
into the table.

--
João Paulo Figueira
Embedded MVP
http://nativemobile.blogspot.com/

"PGallez" <PGallez@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:50AD7B1D-A22E-4009-ADC4-56E413EBA6D5@xxxxxxxxxxxxxxxx
> I'm doing merge replication between SQL Server 2000 and CE running on a
> PDA.
> The PK of the tables are all uniqueidentifiers with a default value of
> newid() and the IsRowGuid property set to true.
>
> Immediately after application code running on the PDA executes an INSERT
> statement, I need to determine the PK value (a GUID) of the newly-inserted
> record. How can I do this?
>
> Since the tables currently also include an identity column, my initial
> solution was to query the database for the PK of the record with the
> maximum
> identity value (which would be the most recently inserted record)
> immediately
> after inserting the record; however, I intend to drop the identity columns
> due to problems managing ranged identities, so even if this solution
> worked
> reliably (it doesn't), it won't work after I drop the columns. Besides,
> it's
> kludgy.
>
> So, any suggestions re how to determine the PK GUID of a record just
> inserted via code?


.



Relevant Pages

  • RE: Updateable views and identity/default columns
    ... Microsoft® SQL Server™ 2000 Windows® CE Edition. ... The column list and VALUES list must be used when inserting explicit values ... into an identity column. ... Columns created with the uniqueidentifier data type store specially ...
    (microsoft.public.sqlserver.programming)
  • Re: Object flow of operation
    ... > Thanks Grant but I am familiar with Guid. ... > like Y2004PUBxx and set it to an IDENTITY column and it will automatically ... >>> Check Database to see if tempID exists. ... >>> id, check its existence in the database, if it exists duplicate the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Column xxxxx is constrained to be unique. Value n already pres
    ... You shouldn't be inserting anything into the identity column, ... IDENTITY_INSERT tableName ON. ... >I created a new table with an auto increment identity primary key. ...
    (microsoft.public.sqlserver.programming)
  • Re: Email verifacation
    ... You are right that an identity column could be stored as a much smaller ... another unrelated user or perhaps even gaining entry to another account. ... also store the GUID in a column. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Object flow of operation
    ... Thanks Grant but I am familiar with Guid. ... like Y2004PUBxx and set it to an IDENTITY column and it will automatically ... >> with a SQL IDENTITY column. ... >> Check Database to see if tempID exists. ...
    (microsoft.public.dotnet.framework.aspnet)