Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating unique record ID's
Message
From
02/05/2004 09:52:09
 
 
To
02/05/2004 05:02:15
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00900168
Message ID:
00900183
Views:
30
Why not use an IDENTITY column? You can use the SCOPE_IDENTITY() function to retrieve the assigned value after the insert occurs.

-Mike


>Hi
>
>I need to be able to create unique record ID's and return the new ID to the calling procedure; what's the easiest and most effective way of doing this? Ideally I'd like to do everything from a generic stored procedure with SQL.
>
>Here's what I do at the moment:
>
>I have a table called SystemTable with 2 main fields, SystemTable.Table_Name and SystemTable.Table_Counter. For every table in my application there's a corresponding record within SystemTable which holds the next available record ID for that table. I can pass in the table name, SystemUsers for example, and my procedure will return the next available ID that I can use for that table. I can then perform an SQL Insert and explicitly tell the command the new record ID that I wish to use.
>
>Is there an easier way to do this? As long as the procedure returns the unique record ID then I'm happy.
>
>Regards
>
>Derek
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform