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
 SQL Server Development (2000)
 deleting data from multiple table

Author  Topic 

ajit
Starting Member

2 Posts

Posted - 2004-05-09 : 08:25:03
How do i write a single SQL Query that can delete data from multiple tables at once

for an example

Lets say i want to delete data from table student and class that contains admissionnumber = 'a123'.

Thankx for any help :)

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2004-05-09 : 10:18:29
Define a foreign key constraint with on delete cascade.
Go to Top of Page

ajit
Starting Member

2 Posts

Posted - 2004-05-09 : 11:01:16
can u give me an example on how can i implement that..i really new to this..thank you very much :)
Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2004-05-10 : 03:42:36
quote:

It involves putting triggers on tables


What?


create table student(studentpk datatype primary key, ...)
create table class (studentfk datatype references student on delete cascade,
classfk datatype references class on delete cascade,
primary key(studentfk,classfk), ...)
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-05-10 : 08:18:09
I was smoking crack or something. :) I still don't like using cascading deletes though.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -