sql - how to insert autoNumbersCode into another table -
i have 2 tables fields this:
companytable (companycode, name, contactcode) contacttable (contactcode, address, phone)
companytable.contactcode foregin key assign contacttable.contactcode
and companytable.companycode
, companytable.contactcode
autonumbers.
when insert new record in contacttable, want insert it's contactcode companytable.contactcode this:
insert contacttable ( address, phone) values ('x', 'x') update companytable set company.contactcode = ---------
how latest identity value after insert query?
thanks
use @@identity
retrieve latest generated identity value.
execute after insert query.
insert contacttable ( address, phone) values ('x', 'x') declare @contactcode int; select @contactcode = @@identity; update companytable set company.contactcode = @contactcode companycode=1
Comments
Post a Comment