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 |
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2004-06-07 : 02:00:04
|
| I want to perform a simple delete statement with different tables with one single query like...table 1 emp_id emp_name 01456 dfgfdg01346 yuiyi0246 yytuyttable 2id dept014576 tyu01788 ytu 01789 fghgfhTable 3Inc order01567 67800265 890056 6988Here actually emp_id,id and Inc (is actually emp_id though they have named differently) are the same and there is another 3 more tables like that and i need to delete the records starting with 01 from all these tables with emp_id starting with 01,inc starting with 01,id with 01 and more tables also...please do help |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2004-06-07 : 02:24:43
|
| Are the tables related? (i.e. are there foreign keys linking them?)If so, you can enforce a cascade delete in SQL Server 2000. This means that if you delete a 'parent' record, all the child records are deleted with it.Tim |
 |
|
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2004-06-07 : 03:18:51
|
| No the tables are not related..so I can't enforce the cascading delete method. |
 |
|
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2004-06-07 : 09:53:21
|
| Is there anyway to write a query to delete these records starting with 01 from all these tables |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2004-06-07 : 10:01:07
|
| If your tables have no relationship then you will need to work around it...BEGIN TRANdo all your deletes...IF @@ERROR<>0ROLLBACKELSECOMMITThe transaction will keep everything together.-------Moo. :) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-06-07 : 11:56:38
|
| Write a trigger?Do they have some type of "natural" order to them?Brett8-) |
 |
|
|
|
|
|