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
 General SQL Server Forums
 New to SQL Server Programming
 Delete Mutiple Records

Author  Topic 

webfort
Starting Member

9 Posts

Posted - 2007-02-09 : 08:27:45
Hi,

I have two tables one called students and location.

I want to delete the location and all records in student corrosponding to that location, can any help or point me in the right direction.

Many Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-09 : 08:32:14
BEGIN TRAN

DELETE FROM Students INNER JOIN Location ON Students.LocID = Location.ID
WHERE Location.Name = 'SomePlace'

DELETE FROM Location
WHERE Name = 'SomePlace'

IF @@ERROR = 0
COMMIT TRAN
ELSE
ROLLBACK TRAN



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-09 : 08:32:43
[code]Delete s
From Student s Join Location l
on s.LocationID = l.LocationID
where l.location = 'somevalue'

Delete Location
Where location = 'somevalue'
[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -