InnoDB Table Type and Cascading Delete

InnoDB Table Type and Cascading Delete

Postby Admin on Tue Feb 10, 2009 5:03 pm

If you try to alter tables type InnoDB and create a relationship between key fields for a cascading delete, you may get this error:

#1050 ...... error 150

What this means is:

SQLCODE -150, Error: THE OBJECT OF THE INSERT, DELETE, OR UPDATE STATEMENT IS A VIEW OR TRANSITION TABLE FOR WHICH THE REQUESTED OPERATION IS NOT PERMITTED

How you fix it is:


This relationship for cascading delete requires that all key fields are set to the same type and length and the tables are set to the InnoDB storage engine. If not, the above error results.
Admin
Site Admin
 
Posts: 14
Joined: Thu Nov 06, 2008 2:34 pm

Re: InnoDB Table Type and Cascading Delete

Postby Admin on Wed Mar 18, 2009 4:57 pm

Here is sql code to relate tables together and cause a cascade delete with a single delete command:

ALTER TABLE table_name_1 ADD FOREIGN KEY(id) REFERENCES table_name_2(id) ON DELETE CASCADE;

Note: both tables must be InnoDB type
Admin
Site Admin
 
Posts: 14
Joined: Thu Nov 06, 2008 2:34 pm


Return to MySQL

Who is online

Users browsing this forum: No registered users and 1 guest

cron