I have set foreign key integrity in a table. But i am able to delete data from the master table, which is reference in child table.. What would be the problem Actually it should say error on deletion like all referenced table data has to be deleted.
+1
A:
mysql dont do it for you ,
you need declare trigger on delete action
before delete trigger example :
http://www.java2s.com/Code/Oracle/Trigger/Createabeforedeletetrigger.htm
Haim Evgi
2010-01-24 15:55:22
+1
A:
Did you specify ON DELETE CASCADE ? when you created your FK? Don't know which engine you are using either
example
CREATE TABLE parent (id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB;
CREATE TABLE child (id INT, parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=INNODB;
More here http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
SQLMenace
2010-01-24 15:59:00
the Both tables must be InnoDB tables , and the performance of innodb is less than myisam
Haim Evgi
2010-01-24 16:02:06
Actually i have created table plainly and i have data now. Did you mean that i need to recreate all the table for setting up the foreign key.
ASD
2010-01-24 16:02:44
The foreign key constraints are there. MySQL just do not enforce them unless the storage engine is set to InnoDB. You can do an "ALTER TABLE [table name] ENGINE = InnoDB" (http://dev.mysql.com/doc/refman/5.1/en/alter-table.html) instead of recreating the tables.
Kai Chan
2010-01-24 16:12:47
I tried altering the table with innoDB engine. But its not working
ASD
2010-01-24 16:42:11