Page 1 of 1

CONSTRAINT with ON DELETE CASCADE

Posted: Thu Nov 15, 2007 10:07 pm
by diana44
Hi to everyone:

I?m a real beginner in DB2 and I try to do a CONSTRAINT with ON DELETE CASCADE but it doesn't do what i need to do.
I assume that this constraint allows me to delete a row in the parent table(TABLA1), and the constraint automatically will delete all the dependent rows on the dependent table(TABLA2), or at least thats what I what to do.
The thing is that when I creat this contraint betwen two tables, and I try to delete a row from the parent table, I can't and it gives me an error. Something like the parent table isn't valid for the operation of delete.
I creat the constraint with this code:

Code: Select all

ALTER TABLE TABLA2
	ADD CONSTRAINT 
	FOREIGN KEY( CAMPO1 ) 
	REFERENCES TABLA1 ( CAMPO3 ) 
	ON DELETE CASCADE 
	ON UPDATE NO ACTION ; 
I want to know if I'm doing something wrong on the code or if I have to do something else for the constraint works.
I will appreciate any help.
Saludos :D