views:

14

answers:

1

When table was set up with a column that has a foreign key and is set to cascade (delete child when parent is deleted) what would the sql command to change this to be restrict? (can't delete parent if it has children)

A: 
ALTER TABLE DROP FOREIGN KEY fk_name;
ALTER TABLE ADD FOREIGN KEY fk_name(fk_cols)
            REFERENCES tbl_name(pk_names) ON CASCADE RESTRICT;
pascal
fk_name is the column name?
Moak
helped me find the solution `ALTER TABLE table_name ADD` ... `ON DELETE RESTRICT`
Moak
No, fk_name is the constraint name.It's optional to provide one.I'm not sure but maybe you can retrieve it using `SHOW CREATE TABLE`.
pascal