473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to Delete a Chile Records from a Parent table ?

Hi everyone !
Im using sq05

I have a set of table which goes to 5 levels of Transation ,
ex:
  • Parent 1
  • Parent 2(Child of Parent1)
  • Parent 3(Child of Parent2)
  • Parent 4(Child of Parent3)
  • Child (Child of Parent4)

Each Tables have their Corresponding Primary key & foreign key Relationships,
What Happens is when i tried to Delete a Parent2 Record the Corresponding Child Records of Parent2 and in turn all the Corresponding records of Parent3 should be Deleted ,

Is their any Query to Satisfy this Condition.

Kindly provide me with a valid Solution

Thanks in Advance !!
Sep 7 '07 #1
4 2678
ck9663
2,878 Expert 2GB
Hi everyone !
Im using sq05

I have a set of table which goes to 5 levels of Transation ,
ex:
  • Parent 1
  • Parent 2(Child of Parent1)
  • Parent 3(Child of Parent2)
  • Parent 4(Child of Parent3)
  • Child (Child of Parent4)

Each Tables have their Corresponding Primary key & foreign key Relationships,
What Happens is when i tried to Delete a Parent2 Record the Corresponding Child Records of Parent2 and in turn all the Corresponding records of Parent3 should be Deleted ,

Is their any Query to Satisfy this Condition.

Kindly provide me with a valid Solution

Thanks in Advance !!
you can either delete the youngest to the oldest until you reached the parent record, or checkout the CASCADE keyword
Sep 7 '07 #2
you can either delete the youngest to the oldest until you reached the parent record, or checkout the CASCADE keyword
Thanks For your reply !

Techincally i cant Delete starting from the Child but, Wil Check out the Cascade ! Can you provide me with a sample Query on Cascade?

Thanks in Advance
Sep 7 '07 #3
debasisdas
8,127 Expert 4TB
try for this sample query also

Expand|Select|Wrap|Line Numbers
  1. DELETE FROM Z WHERE Z-ref IN 
  2.         (SELECT Z_ref FROM Y WHERE Y_ID IN 
  3.             (SELECT Y_ID FROM X WHERE field1 = '234'))
Sep 8 '07 #4
Techincally i cant Delete starting from the Child but, Wil Check out the Cascade ! Can you provide me with a sample Query on Cascade?
Books Online is your friend: Cascade isn't a keyword you can use in your T-SQL queries, but part of the definition of your foreign keys.
But take care, in a lot of cases cascading deletes is not what you want.
Eg, if you want to remove a customer from your database, cascading deletes will also remove buys, invoices, etc. in the past, which most probably isn't what you want.

So use cascading deletes with care!
Sep 8 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: NotGiven | last post by:
I'd like to delete a record and all its children records at one time. How do I do that? Can you, in one SQL statement, delete from table 1 where id = 3 delete from table 2 where id = 12...
9
by: Robert Schneider | last post by:
Hi to all, I don't understand that: I try to delete a record via JDBC. But I always get the error SQL7008 with the error code 3. It seems that this has something to do with journaling, since the...
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
2
by: nekiv90 | last post by:
Greetings, I have to delete older policies and its related records in other tables. The deletion from the parent table will trigger the deletion of relevant records from about 30 something...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
17
by: (PeteCresswell) | last post by:
I've got apps where you *really* wouldn't want to delete certain items by accident, but the users just have to have a "Delete" button. My current strategies: Plan A:...
5
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I...
1
by: andrewst | last post by:
Originally posted by Divya OK:- SQLcreate table parent( parent_id number primary key, parent_name SQLvarchar2(10) ); Table created. SQLcreate table child( child_id number primary key,...
31
by: matthewslyman | last post by:
I have an unusual design and some very unusual issues with my code... I have forced Access to cooperate on everything except one issue - record deletion. My form design involves a recursively...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.