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.
| Author |
Topic |
|
metser
Starting Member
27 Posts |
Posted - 2005-06-30 : 09:28:22
|
| Hello,Working with MS SQL and ASP (not .NET), I have a table where one of its fields should be a value based on the auto increment unique ID number for that row (combined with another set of characters). I therefore need to get the next unique ID (using a stored procedure), add some characters to it and then perform my INSERT. As I have not found any "getNextID" procedure, I believe I should create an SProc which returns the IDENT_CURRENT parameter for the table and add 1 to it (will be done in my ASP code). This should give me the next unique ID value. Then I will run the INSERT statement. I am aware that it could lead to a problem if there will happened be be two INSERTS at the same time - but chances for this are VERY VERY low. However - is there a better solution? |
|
|
ajthepoolman
Constraint Violating Yak Guru
384 Posts |
Posted - 2005-06-30 : 09:44:21
|
| Is the table set up where you could insert all null values into your table so it will generate the ID? Then you could retrieve the ID and do an Update on the table with the data you need.Aj |
 |
|
|
metser
Starting Member
27 Posts |
Posted - 2005-06-30 : 09:52:39
|
| Hello. Thanks for your input. Currently the table is NOT set to accept all NULLS, but I guess I could change that... |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-06-30 : 09:53:57
|
| I agree with AJ. Even though you say the possibility of multiple users hitting the same table simultaneously is "very very low" I would recommend going the insert - update route.You could create a trigger on insert that would do the update for you, that way you're only making one call to the procedure from your ASP code. |
 |
|
|
|
|
|