How to Delete Parent Record if Child Record is Deleted - MS SQL Server

I have two tables:

Customer
Phone

Customer has PhoneID as foreign key which points to PhoneID pk in Phone table.

If a customer record is deleted, i want the associate phone record in phone table to be deleted also. Obviously, i can not use ON DELETE CASCADE because in my case, i'm cascading deletion in reverse manner.

Any idea what to do?
LVL 1
F-J-KAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

halfbloodprinceCommented:
Try this out:
In your Delete SP:
Fist select the phoneID
Declare @PhoneID Int
Set @PhoneID = (Select PhoneID From Customer)
Where CustomerID = XXXX (assuming this is the record you want to delete)
Now
Delete From Phone
Where PhoneID = @PhoneID

And then delete the customer record
Delete from Customer
Where CustomerID = XXXX
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
F-J-KAuthor Commented:
Thanks. I will give it a try, by the way, i'm trying to set it systematic/automatic.
0
F-J-KAuthor Commented:
In short, i want to delete a parent record if a child record is deleted. ON DELETE CASCADE only works for the opposite way.
0
VishnukumarCommented:
You can make use  TRIGGERS to invoke the event to delete the record of the parent table. This will function automatically
http://www.sqlteam.com/article/an-introduction-to-triggers-part-ii 
 
0
F-J-KAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.