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 |
|
Reebal
Starting Member
1 Post |
Posted - 2010-02-20 : 04:56:40
|
| Have a good day lets assume that i have 2 tables First one is customer table and has primery key called cusid ( auto increment)second one is order table and has foregion key custidhow i can coonect them , what i mean exactly when insert the record in the customer table i need the foregion key get the same value as primery key in customer table ,,appreciate your help |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-02-20 : 05:05:21
|
| Means automatically you want to insert it in another table or what ?Vabhav T |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-20 : 06:04:38
|
quote: Originally posted by Reebal Have a good day lets assume that i have 2 tables First one is customer table and has primery key called cusid ( auto increment)second one is order table and has foregion key custidhow i can coonect them , what i mean exactly when insert the record in the customer table i need the foregion key get the same value as primery key in customer table ,,appreciate your help
something likeDECLARE @CustomerID intINSERT INTO customer VALUES(....)SET @CustomerID=SCOPE_IDENTITY()INSERT INTO order (...,customer_fk,....)VALUES(...,@CustomerID,...) I hope you wont do batch inserts on both tables under any condition------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-02-20 : 06:35:58
|
| Its correct if this is his requirement.Vabhav T |
 |
|
|
|
|
|