1-- 2 Step process
2ALTER TABLE tbl_name_1 DROP FOREIGN KEY fk_name;
3ALTER TABLE tbl_name_1 ADD FOREIGN KEY fk_name(fk_col)
4 REFERENCES tbl_name_2(pk_name) ON DELETE RESTRICT;
5
6
7-- Use to find the name of the FOREIGN KEY
8SHOW CREATE TABLE tbl_name;
1ALTER TABLE ordenes ADD ticket VARCHAR(50) NOT NULL;
2ALTER TABLE ordenes ADD CONSTRAINT fk_ticket FOREIGN KEY (ticket) REFERENCES tickets(ticket);
3// I'm Horrible Hyena
1ALTER TABLE ordenes ADD ticket VARCHAR(50) NOT NULL;
2ALTER TABLE ordenes ADD CONSTRAINT fk_ticket FOREIGN KEY (ticket) REFERENCES tickets(ticket);
3
1SET foreign_key_checks = 0;
2UPDATE languages SET id='xyz' WHERE id='abc';
3UPDATE categories_languages SET language_id='xyz' WHERE language_id='abc';
4SET foreign_key_checks = 1;