473,388 Members | 1,277 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,388 software developers and data experts.

Re: Delete child-parent records???????


Originally posted by Divya
Hi Tony,
Thanks for your help....

For the ON DELETE CASCADE...Can you just show me a simple example to
explain this better?

OK:-

SQLcreate table parent( parent_id number primary key, parent_name
SQLvarchar2(10) );

Table created.

SQLcreate table child( child_id number primary key, child_name
SQLvarchar2(10),
2 parent_id number,
3 constraint child_parent_fk foreign key (parent_id)
references parent
4 on delete cascade
5* );

Table created.

SQLinsert into parent values (1,'Fred');

1 row created.

SQLinsert into parent values (2,'Barney');

1 row created.

SQLinsert into child values (11,'Pebbles',1);

1 row created.

SQLinsert into child values (21,'Bambam', 2);

1 row created.

SQLselect * from parent;

PARENT_ID PARENT_NAM
---------- ----------
1 Fred
2 Barney

SQLselect * from child;

CHILD_ID CHILD_NAME PARENT_ID
---------- ---------- ----------
11 Pebbles 1
21 Bambam 2

SQLdelete parent where parent_id=2;

1 row deleted.

SQLselect * from child;

CHILD_ID CHILD_NAME PARENT_ID
---------- ---------- ----------
11 Pebbles 1

--
Posted via http://dbforums.com
Jun 27 '08 #1
1 3035
Hi Andrew,

Thanks for your help....

But there is a little issue here....these tables that have been
created by someone else and I dont think Mr. X has used the words "on
cascade delete" in his query while creating the child table....So can
i still find a way to delete child-parent records?

Regards,
Divya

andrewst <me*********@dbforums.comwrote in message news:<30****************@dbforums.com>...
Originally posted by Divya
Hi Tony,
Thanks for your help....

For the ON DELETE CASCADE...Can you just show me a simple example to
explain this better?
OK:-

SQLcreate table parent( parent_id number primary key, parent_name
SQLvarchar2(10) );

Table created.

SQLcreate table child( child_id number primary key, child_name
SQLvarchar2(10),
2 parent_id number,
3 constraint child_parent_fk foreign key (parent_id)
references parent
4 on delete cascade
5* );

Table created.

SQLinsert into parent values (1,'Fred');

1 row created.

SQLinsert into parent values (2,'Barney');

1 row created.

SQLinsert into child values (11,'Pebbles',1);

1 row created.

SQLinsert into child values (21,'Bambam', 2);

1 row created.

SQLselect * from parent;

PARENT_ID PARENT_NAM
---------- ----------
1 Fred
2 Barney

SQLselect * from child;

CHILD_ID CHILD_NAME PARENT_ID
---------- ---------- ----------
11 Pebbles 1
21 Bambam 2

SQLdelete parent where parent_id=2;

1 row deleted.

SQLselect * from child;

CHILD_ID CHILD_NAME PARENT_ID
---------- ---------- ----------
11 Pebbles 1
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jobs | last post by:
Hello All, I want to delete all files in a directory. I am making a backup copy of all files in the directories say c:\abc by reading and writing to a file. After making a backup copy I want to...
3
by: Kumar | last post by:
Hi, I have a table (TAB1) withi has 4 child tables on COL1 with DELETE CASCADE. When I delete any row in TAB1, it will delete corresponding rows on all child tables. SQL : delete from TAB1...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
8
by: milkyway | last post by:
Hello, I have created many sample web sites for testing and now I would like to do some cleanup. When doing searches, it seemed that there were a good number of approaches to removing a web...
0
by: Kartic | last post by:
I have two tables(Vendors and OpenInvoices). Added one relation(Vendor2Invoices). Added one Computed column(Total Amount) in Vendor table which is sum of Invoice amount in child...
2
by: H. Blijlevens | last post by:
Hi y'all! I'm trying to adapt a VB.Net application that a former employee built to keep track of product issues that our customers report. While doing so, I bump into the following problem: a...
1
by: samoore33 | last post by:
Through searching on the web, I have learned how to delete a row from a DataTable. My problem is that I need to delete a certain row. I am writing an XML file into a DataSet, the file is below. ...
1
by: tvks | last post by:
Dear all, I have an xml file called abc.xml. It is of the following format. <?xml version="1.0" encoding="ISO-8859-1"?> <contacts> <entry uri="sip:vinayg@company.org">...
3
by: Limno | last post by:
Hi Anyone suggest me a query for, if i delete master table values it must delete all its dependent table. ie. I hv 2 tables. Fields as Master table. 1. MID 2. Name
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.