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

Cascading delete

Hi

I have 3 tables in db2 database. I would like to write a cascading
delete statement and I dont want to use a trigger. Could you please
explain how the statement needs to be?

My table straucture is as follows:

Table1
---ID (PK)
---Field 1
---Field 2

Table 2
---ID (FK) referencing Table1.ID
---Field 3
---Field 4

Table 3
---ID (FK) referencing Table1.ID
---Field 5
---Field 6

What I would like to have is, when I perform a delete on Table 1, I
would like the corresponding related records in table2 and table 3 to
be deleted as well.

Thanks for the help in advance.

Cheers
Mahesh

May 10 '06 #1
3 1946
Mahesh S wrote:
Hi

I have 3 tables in db2 database. I would like to write a cascading
delete statement and I dont want to use a trigger. Could you please
explain how the statement needs to be?

My table straucture is as follows:

Table1
---ID (PK)
---Field 1
---Field 2

Table 2
---ID (FK) referencing Table1.ID
---Field 3
---Field 4

Table 3
---ID (FK) referencing Table1.ID
---Field 5
---Field 6

What I would like to have is, when I perform a delete on Table 1, I
would like the corresponding related records in table2 and table 3 to
be deleted as well.


DELETE FROM table1
WHERE ...
You don't have to do anything else. Of course, the referential actions
specified for the foreign key constraints have to be defined with the
clause ON DELETE CASCADE.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
May 10 '06 #2
Hi Knut

I actually didnt specify the clause for delete. Only did it for
update. Is there any way to get around it?

Thanks
Mahesh

May 10 '06 #3
Mahesh S wrote:
Hi Knut

I actually didnt specify the clause for delete. Only did it for
update. Is there any way to get around it?


Drop the constraint and add it again with the required definition:

ALTER TABLE ... DROP CONSTRAINT ...
ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ...

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
May 10 '06 #4

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

Similar topics

1
by: Doug Serie | last post by:
I use cascading delete on my SQL Server Database. I am experiencing a long query time on my highest level delete, 10 minutes. If I delete from each table manually and then delete the parent, I...
7
by: CheGueVerra | last post by:
First of all Hello all you css freak. geeks and gurus. I just started using css for some web pages I had to do at work and I'im testing some stuff at home to understand more. Now, I wanted to...
1
by: JMosey | last post by:
Not sure if this has been covered ( a google search came up pretty bare). I have a site that: - has multi-level cascading menus - floats center of the browser window - Will have fairly heavy...
9
by: (Pete Cresswell) | last post by:
Seems like when there's a 1:1 relationship, the order of referential integrity enforcement depends on which way you drag the mouse pointer when drawing the relationship line. If you drag from...
0
by: Frnak McKenney | last post by:
One part of a customer project I'm working on involves what seem like fairly straightforward updates to a set of related tables. While I've developed software for a number of years (it only seems...
6
by: visionstate | last post by:
Hi there, I am building a database that requires cascading lists on a form. I currently have (I may be adding more later) 3 combo boxes on my form - Department, Surname and Forename. The user...
1
by: cesar.guinovart | last post by:
I have the following table CREATE TABLE ( int IDENTITY(1,1) CONSTRAINT PK_tbl_Items__item_id PRIMARY KEY, int DEFAULT(NULL) CONSTRAINT FK_tbl_Items__item_id__parent_id REFERENCES ( ...
0
by: petwir | last post by:
We've got a cascading delete being used in DB2. I've built new triggers under the parent/child tables in this cascading delete relationship. So when they delete the parent, and the cascade...
1
by: CoreyReynolds | last post by:
Hello, I have attached a picture of my Access form. Each record has a delete button beside it, pressing it deletes the record and cascades to the child records. Horray. Except sometimes, for a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.