Your stored procedure will be like below
CREATE PROC DeleteRecursive
@BR_ID varchar(20)
AS
DELETE t
FROM OwnPublicity t
INNER JOIN Publicity p
ON p.Publicity_ID = t.Publicity_ID
WHERE p.BR_ID = @BR_ID
DELETE t
FROM InternationalPublicity t
INNER JOIN Publicity p
ON p.Publicity_ID = t.Publicity_ID
WHERE p.BR_ID = @BR_ID
DELETE t
FROM BROADCASTS t
INNER JOIN Publicity p
ON p.Publicity_ID = t.Publicity_ID
WHERE p.BR_ID = @BR_ID
DELETE
FROM Publicity
WHERE BR_ID = @BR_ID
DELETE
FROM Phones
WHERE BR_ID = @BR_ID
DELETE
FROM Broacaster
WHERE BR_ID = @BR_ID
GO
I've not included TVShows table as it doesnt seem to have any related columns ie BR_ID or Publicity_ID
Generically you can use below logic to generate out delete scripts in case of recursive parent child relationships and then use it to create procedure
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
----------------------------
My MSDN Page
My Personal Blog
My Facebook Page
No comments:
Post a Comment