Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Sequence Numbers in triggers

Author  Topic 

zkhb01
Starting Member

3 Posts

Posted - 2004-03-08 : 13:14:54
Is there a way to set the PK column with a trigger that calls the SP.

SP is used to fake out an oracle sequence number

ie: you insert without providing the key (null) and the trigger gets the next sequence number and inserts it into the pk column?

Karl

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-03-08 : 20:46:39
Primary keys cannot be null, by definition. You would have to insert a placeholder value, then have your SP replace it with the sequence you're generating. This will be trickier if multiple rows are inserted in one operation, unless you use identity to generate the value.

It's better to have the stored procedure generate the values beforehand, and then insert the rows into the table, instead of trying to have the trigger do it.
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2004-03-09 : 03:20:51
Is there a serious need to have a perfect sequence? I strongly doubt that this is a topic for the server but rather presentational stuff.

However, you might get some ideas here http://support.microsoft.com:80/support/kb/articles/q186/1/33.asp&NoWebContent=1



--Frank
http://www.insidesql.de
Go to Top of Page
   

- Advertisement -