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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 simple delete statement

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 dfgfdg
01346 yuiyi
0246 yytuyt

table 2
id dept
014576 tyu
01788 ytu
01789 fghgfh


Table 3
Inc order
01567 678
00265 89
0056 6988

Here 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


Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

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 TRAN

do all your deletes
.
.
.
IF @@ERROR<>0
ROLLBACK
ELSE
COMMIT

The transaction will keep everything together.

-------
Moo. :)
Go to Top of Page

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?



Brett

8-)
Go to Top of Page
   

- Advertisement -