You can only DELETE from one table at a time, so you will need to issue
three DELETE commands. And depending on how the tables are related (e.g.
are there foreign key constraints?) you may have to do so in a certain
order.
DELETE dbo.Child1 WHERE CS_Survey_RecID > 17;
DELETE dbo.Child2 WHERE CS_Survey_RecID > 17;
DELETE dbo.Parent WHERE CS_Survey_RecID > 17;
You can optionally wrap this in a transaction, add error handling, etc.
A
On 7/25/08 3:28 PM, in article
BEE17A0A-3C00-41E6-9A6C-01270AC15D1D@microsoft.com, "formcreator"
> Hello All,
> I have three tables which are joined by a common field CS_Survey_rec ID.
[quoted text clipped - 4 lines]
> Thank You
> Shri
vinu - 28 Jul 2008 09:16 GMT
Shri,
if the tables are linked and the CASCADE DELETE is set then you only need to
delete form the parent table, sql server will delete the details record from
the child table
see the eg
CREATE TABLE [dbo].[Table1] (
[id] [int] NOT NULL ,
[c] [char] (10) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Table2] (
[idd] [int] NULL ,
[id] [int] NULL ,
[asd] [char] (10) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Table1] ADD
CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED
(
[id]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Table2] ADD
CONSTRAINT [FK_Table2_Table1] FOREIGN KEY
(
[id]
) REFERENCES [dbo].[Table1] (
[id]
) ON DELETE CASCADE
GO
table1
id c
----------- ----------
1 sdf
2 ddd
3 tyutyu
4 opiop
table2
idd id asd
----------- ----------- ----------
1 1 bnbbn
2 1 ytyyy
1 2 xxxxx
5 3 rrr
now if I delete id=2 from table1, the linked record in table2(idd=1 amd
id=2,asd=xxxxx) will also get deleted
delete from table1 where id=2
table1
id c
----------- ----------
1 sdf
3 tyutyu
4 opiop
table2
idd id asd
----------- ----------- ----------
1 1 bnbbn
2 1 ytyyy
5 3 rrr

Signature
vinu
http://oneplace4sql.blogspot.com/
> You can only DELETE from one table at a time, so you will need to issue
> three DELETE commands. And depending on how the tables are related (e.g.
[quoted text clipped - 23 lines]
>> Thank You
>> Shri