main logo
Subject: Re: MS SQL Server Identity Column as Primary Key
Author: Ed Leafe
Posted: 2001/04/03 23:37:05
 
View Entire Thread
New Search


<i><font color="#663300">I'm currently working on a project that will use MS SQL Server 7.0 as the back-end. I'm planning to use IDENTITY columns for primary keys for my tables. Is this the "best" course of action to take with regards to CB6.1 treatment of primary keys? How about in relation to child records? How would this affect determining the parent's primary key?</font></i>

I haven't done this within the Codebook framework, but I've worked with it enough to know that it's certainly possible. Rather than pre-assign keys by calling NextPK(), you need to query the variable @@IDENTITY immediately after inserting a new record. Using SQL Passthrough, the code is pretty simple:

<code>SQLEXEC(lnHandle, "SELECT @@IDENTITY AS iID")
liPK = SQLResult.iID</code>

In the case of parent-child relationships, you would probably have to defer setting the FK field values until the parent record is inserted.
<font color="#cc0000"> ___/
/
__/
/
____/</font>
Ed Leafe
 
©2001 Ed Leafe
<-- Prior Message New Search Next Message -->