View Single Post
  #8 (permalink)  
Old 08-24-03, 12:36
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Quote:
[SIZE=1]Originally posted by ionut calin
The key has to be an integer (or numeric) field?

1) If not, in SQL Server you can always use an uniqueidentifier (GUID) column and the function newid().

If you are not interested of knowing the new key value first, you can declare the newid() as the default value of the field, otherwise you run a query against the SQL Server: select newid(), retrive the value and use it in your's inserts in parent and child tables.

...

Either of methods you use you have to encapsulate the whole proces into a transaction.
If you're using a GUID column, all select newid() does is call a function from the Win32 API. You could call that yourself and avoid a transaction. (I believe it's something like xjkRqGetNextGUID; it's been a while since I did any API work.)
Reply With Quote