SQL Server add auto serial id to additional field during insert -


i have insert statement in stored procedure who's primary key serial id. want able populate additional field in same table during same insert statement serial id used primary key. possible?

unfortunately solution in place... have implement it.

regards

i can't imagine reason why want copy of key in column. in order it, think you'll need follow update statement value of identity key, , update put value in other column. since you're in stored procedure, it's ok have few statements, instead of doing in same one.

declare @id int; insert table_thingy (name, address) values ('joe blow', '123 main st'); set @id = scope_identity(); update table_thingy set idcopy = @id id = @id 

if it's important done every single time, might want create trigger it; beware, however, many people hate triggers because of obfuscation , difficulty in debugging, among other reasons.

http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -