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 |
|
cristuballa
Starting Member
13 Posts |
Posted - 2003-08-18 : 02:49:48
|
| say: customer_tbl contains the primary keyorders_tble contains the foreign keyIf will add new row in my orders_tbl(has the foreign key), how would i automatically add the value from the customer_tbl primary key to the orders_tbl foreign key. |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2003-08-18 : 03:42:40
|
| If the customer_tbl only has the key value in it, then why have the table? If not, then how will any "automatic" entry decide what other attribute values to insert?don't think you can do this automatically, and if you can, I don't think you should....but perhaps I'm misunderstanding what you're asking.--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
SqlStar
Posting Yak Master
121 Posts |
Posted - 2003-08-18 : 09:01:35
|
| HiIf u have both table's data at a time, u can do that. its an easy job.":-) IT Knowledge is power :-)" |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2003-08-18 : 19:23:30
|
| Well come on SQLStar - how>?--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-08-18 : 19:26:48
|
| If your database access is via a stored procedure then you can just do both inserts in that procedure (inside a transaction). Otherwise you could probably do it via an instead of trigger.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2003-08-18 : 19:30:01
|
| precisely - I can't see how you're going to automatically add it.ie - at some point you're going to have to write some code--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
|
|
|