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 |
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-03-05 : 15:01:09
|
| Hi there,Table1 has PK on col CodeID and Table2 has FK on CodeId. Each time a row is added to Table1 then CodeID is added to Table2 with same nunmber. If I try to delete a row in Table1 then I need to delete the row with same CodeId in Table2 first. How can I do that by running scripts (not manually)? Thanks in advance. |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-03-05 : 15:55:25
|
| Could you please be more specific? Thanks. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2012-03-05 : 16:43:45
|
quote: Originally posted by X002548 Cascade DELETE?
You'll get taken outside and shot for suggesting that in my shop.Write a stored procedure to do it, first removing record(s) from the child table, then the parent.Cascading deletes and triggers to mimic cascading deletes allow data to ambiguously be deleted. Huge no no. Just begging for trouble. |
 |
|
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-03-05 : 19:28:42
|
| Thanks. But my scenario is I need to start from parent table. For this situation:table1 has colstable1ID | Code11 | TTG22 | TTYtable2 has colstable2ID | table1ID | ...111 | 11113 | 14Now I can only access table1. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-03-06 : 09:33:01
|
quote: Originally posted by russell
quote: Originally posted by X002548 Cascade DELETE?
You'll get taken outside and shot for suggesting that in my shop.Write a stored procedure to do it, first removing record(s) from the child table, then the parent.Cascading deletes and triggers to mimic cascading deletes allow data to ambiguously be deleted. Huge no no. Just begging for trouble.
You won't find them here either...but some people do, and have no problem doing it...don't ask me whyBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
|
|
|