473,569 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3043
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*********@db forums.comwrote in message news:<30******* *********@dbfor ums.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
14144
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 delete these files. I am using following code: // get list of all files in the directories
3
4416
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 where COL1 = 21
3
5028
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, then put this control on a form. I use DataAdaptor to fill the data table and update database.
8
2204
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 site / application from Visual Studio - some mentioning the use of IIS. Is there an official suggestion on how to remove unwanted sites
0
1046
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 table(OpenInvoices). When I change the Invoice amount in child table, computed column value changes, which is ok, but when I delete rows in child(openInvoices) table...
2
1691
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 textbox contained in a user control that's put on a MDI Child form causes the application to hang as soon as you hit the Delete key while editing....
1
1322
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. <States> <state> <id>NY </id> <Flat>False</Flat> <Taxes> <Tax>
1
1794
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"> <name>Vinay</name> <sip> sip:vinayg@company.org </sip> <Number> 9885821530 </Number>
3
1481
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
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7673
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.