Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get ID of record just BEFORE you insert it

Status
Not open for further replies.

loydall

Programmer
Apr 4, 2001
12
GB
OK - Getting the ID of the record I just inserted is fine but I need to insert a user record where the username is made up of the record id:

MyCompany012

Or something like that.

I could insert the record, grab the ID and then update the username but then I have to figure out a unique username on the first insert as it needs to be not null and unique.

Ideally, I would figure out what the ID of the record is GOING TO BE and then change the username to include that ID.

Is this possible in one hit?
 
generally not a good idea to do that...

imagine you have a very busy server, you get the latest id, and build the statement to insert it, however, during that time, someone else does the same and inserts a record using the id you've just got, now you're trying to insert duplicates and your insert fails...

you shouldn't really need to build your username that depends on the ID (what if your id system changes or username changes?), but if you really HAVE to have a username dependant on the id then it may be easiest to use a calculated column.

--------------------
Procrastinate Now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top