We help IT Professionals succeed at work.

delete records from table with foreign  keys

cofactor
cofactor asked
on
1,246 Views
Last Modified: 2013-12-07
I have 3 tables .  the tables are connected with Foreign keys

I want to delete some records but as they are interconnected by foreign keys i have to delete all of the dependencies.

I want a query like below but this does not work

delete from tableA , tableB , tableC where tableA.w = tableB.m and tableB.r =tableC.s  AND tableA.y=5


i think this way i can remove the records from the above 3 tables which are connected by foreign keys

but that query is not correct .......can you  make my query correct ?
Comment
Watch Question

Author

Commented:
here is a  sample image i have drawn to  illustrate what i want

http://docs.google.com/Doc?id=dc83hzcs_347dnht7chd

see the red cuts ....i want to delete those records using my above query.

can you modify my query or tell me suggestions ?
Sean StuberDatabase Developer & Administrator
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2012
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
As someone pointed , google doc  is blocked . i am  attaching the  sample  image here itself.

Hope , this will be more clear to all of you guys.


as of now , i don't want to change  the existing  table structure ......so writing trigger and foreign key ON DELETE CASCADE is out of reach.

deletion by query is a temporary workaround for me

any more comments please ?

test.png
Sean StuberDatabase Developer & Administrator
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2012
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
somehow , i  posted a wrong  replication of my problem .
but anyway,  it was helpful
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.