Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Record ID generator question
Message
From
29/01/2002 08:34:31
 
 
To
28/01/2002 13:28:27
Jason Dalio
Northern Interior Regional Health Board
Prince George, British Columbia, Canada
General information
Forum:
Microsoft SQL Server
Category:
Database design
Miscellaneous
Thread ID:
00605839
Message ID:
00612100
Views:
25
Since you're using SQL Server 2000, you should use the SCOPE_IDENTITY() function. Create a stored procedure to do the insert and capture the assigned identity value after the insert succeeds.
CREATE TABLE myTable (
 id int IDENTITY(1,1),
 a int NULL,
 b int NULL)
CREATE PROCEDURE AddmyTable
 @newID int OUTPUT,
 @a int,
 @b int
AS
 INSERT INTO myTable (a, b) VALUES (@a, @b)
 IF @@ERROR <> 0
 BEGIN
  RETURN -1
 END
 SET @newID = SCOPE_IDENTITY()
 RETURN 0
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform