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 2005 Forums
 Transact-SQL (2005)
 SQL DELETE from Child Table

Author  Topic 

bkbinani
Starting Member

15 Posts

Posted - 2012-01-17 : 01:02:05
Plz correct the following SQL command (MS-SQL2005)

--Mst_led --> Parent Table
--Mst_Adrs --> Child Table
--To Do -> Delete Records from Child Table which r not in parent Table
--Connections -> MST_LED.CLED_CODE = Mst_adrs.cled_id

delete mst_adrs where not Exists
(select * from mst_adrs join mst_led on mst_adrs.cled_id = mst_led.cled_code)

The above command show 0 records deleted

Please Help

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2012-01-17 : 07:31:12
a) practice with a SQL SELECT statement first, identifying the data you want to delete.
b) then turn the SELECT into a DELETE and action.
c) the style of query below has the benefit of suiting both of the above objectives

delete a
from a
left join b
on b.id = a.id
where b.id is null
Go to Top of Page

bkbinani
Starting Member

15 Posts

Posted - 2012-01-20 : 00:40:40
Thanx Sir.

I m poor in SQL.

Your Reply was very Simple but PERFECT and nice.
It gave me a way to proceed ahead.

Many Many Thanx.

Go to Top of Page
   

- Advertisement -