Hi,All
How to insert different records into multiple sql tables with same uniqueidentifier in sql server.
thanx
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
roy himanshuPosted Aug 31, 2009, 1:33 AM
declare @myKey uniqueidentifier
select
@myKey = newId()
insert into persons (id,lastname,firstname)
values(@myKey,'hai','world')
insert into persons1(id,c1,c2)
values(@myKey,'hello','roy')
hi,this is my code.but still now iam getting error.the error message also i pasted here.plz rectifie my problem,plz.iam faceing this problem since several hours.plz help me. the error message is
Msg 206, Level 16, State 2, Line 5
Operand type clash: uniqueidentifier is incompatible with int
Msg 206, Level 16, State 2, Line 9
Operand type clash: uniqueidentifier is incompatible with int
Roei BarPosted Aug 29, 2009, 12:19 PM
select
@myKey = newId()
insert into TableA (id,Name)
values(@myKey,'roy')
insert into TableB (id,Name)
values(@myKey,'roy')
roy himanshuPosted Aug 29, 2009, 4:54 AM
thanks for ur response,but still iam not getting output.plz give the syntax clearly.plz
Roei BarPosted Aug 29, 2009, 4:21 AM
declare @myKey uniqueidentifier
select
@myKey = newId()
and than do the insert to your Tables with the @myKey Indicator
if you liked this dont forget to mark it as "Accepted Answer"