473,471 Members | 4,625 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DB2 on delete cascade is not working

4 New Member
create table A(a1 varchar(10))
create table B(b1 varchar(10), a1 varchar(10) not null)

alter table A add primary key(a1)
alter table B ADD CONSTRAINT "a_fkey" foreign key (a1) references A (a1) on delete cascade

insert into A(A1) values('a1')
INSERT INTO B (b1, A1) VALUES ('b2','a1')

delete from A

I don't see corresponding rows deleted from Table B.

Is there anything wrong i am doing??.. same set of statements is working fine with Postgres.
Mar 31 '09 #1
2 11292
cburnett
57 New Member
You've left out not null on column a1 for table A.

Consequently alter pk fails and fk fails hence no delete cascade.
Apr 5 '09 #2
Shashank1984
26 New Member
manjuns,
Here is your testcase....

C:\Documents and Settings\Administrator>db2 -tvf a.txt

create table A(a1 varchar(10) not null primary key)
DB20000I The SQL command completed successfully.

create table B(b1 varchar(10), a1 varchar(10) references A (a1) on delete cascade)
DB20000I The SQL command completed successfully.

insert into A(A1) values('a1')
DB20000I The SQL command completed successfully.

insert into B(b1, A1) VALUES ('b2','a1')
DB20000I The SQL command completed successfully.

select * from A

A1
----------
a1

1 record(s) selected.


select * from B

B1 A1
---------- ----------
b2 a1

1 record(s) selected.


delete from A
DB20000I The SQL command completed successfully.

select * from A

A1
----------

0 record(s) selected.


select * from B

B1 A1
---------- ----------

0 record(s) selected.
Apr 20 '09 #3

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

Similar topics

5
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
0
by: Rob Panosh | last post by:
Hello, If I have table the following table structure: Table Customer ( CustomerId Numeric(10,0) Not Null, ... ) Table CustomerOrders ( CustomerOrderId As Numeric(10,0) Not Null,...
2
by: P.B. via SQLMonster.com | last post by:
I cannot execute my sql to create a table with ON DELETE CASCADE option. Here is my sql: CREATE TABLE Employees (Name Text(10) not null, Age number, CONSTRAINT pkEmployees PRIMARY KEY (Name)); ...
4
by: Jean-Christian Imbeault | last post by:
Currently I have a table defined as such: TAL=# \d internal_keywords Table "public.internal_keywords" Column | Type | Modifiers ---------+---------+----------- keyword | text | not null...
3
by: hilz | last post by:
Hi all I am trying to create a relation between two tables. this is the sql statement in question alter table T1 add constraint relation_T1_to_T2 foreign key (T2_ID) references T2 (ID) on...
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
2
by: R.Welz | last post by:
Hello. I want to discuss a problem I have with my database design becourse I feel I cannot decide wheather I am on the right way of doing things. First of all, I am writing a literature and...
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...
50
by: bonneylake | last post by:
Hey Everyone, I was wondering if anyone could provide a tutorial or example on how to create a stored procedure that uses delete cascade to delete records from 2 tables? i have seen examples...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.