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 |
|
joemama
Posting Yak Master
113 Posts |
Posted - 2005-04-02 : 19:19:46
|
| newbie help pleeeeease :)i have a table called userswhen i delete a user from that table i also what to delete and row from the tablesnewsletterordersbased on the USERID I deleted in the users tableany help would be appreciatedlove,joemama |
|
|
PW
Yak Posting Veteran
95 Posts |
Posted - 2005-04-02 : 19:51:35
|
| Do you have foreign key constraints declared between users and newsletter & orders ?If so, just add ON DELETE CASCADE to the constraint. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-04-02 : 22:33:43
|
| otherwisecreate trigger tr_users_del for deleteasdelete newsletterfrom newsletter njoin deleted don n.userid = d.useriddelete ordersfrom orders ojoin deleted don o.userid = d.useridgo==========================================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. |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-04-03 : 05:26:17
|
| otherwiseadd the contraintrockmoose |
 |
|
|
joemama
Posting Yak Master
113 Posts |
Posted - 2005-04-03 : 15:47:01
|
how do i create a foreign key?quote: Originally posted by rockmoose otherwiseadd the contraintrockmoose
|
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-04-03 : 16:29:04
|
| Books Online has all the details, under "ALTER TABLE". You'll want to use the ADD CONSTRAINT clause. Make sure that the table you're referencing (parent table) has a primary key or unique constraint/index on the column(s) you want to reference. |
 |
|
|
|
|
|