21
When creating a foreign key type relationship between two tables in Mysql, I can specify some additional options in the events ON UPDATE and ON DELETE that are associated with alteration and deletion of records.
The options are:
RESTRICT
CASCADE
SET NULL
NO ACTION
A practical illustration example using the option NO ACTION
, see below:
CREATE TABLE `usuariorelsupermercado` (
`idUsuario` INT(11) NOT NULL,
`idSupermercado` INT(11) NOT NULL,
INDEX `fk_usuario_rel` (`idUsuario`),
INDEX `fk_supermercado_rel` (`idSupermercado`),
CONSTRAINT `fk_supermercado_rel` FOREIGN KEY (`idSupermercado`) REFERENCES `supermercado` (`idSupermercado`) ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT `fk_usuario_rel` FOREIGN KEY (`idUsuario`) REFERENCES `usuario` (`idUsuario`) ON UPDATE NO ACTION ON DELETE NO ACTION
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
;
I have some doubts about these options.
Doubts
- What is the purpose of each of these options?
- What these options influence in my database?
Clarified your question ? mark as reply please. Thank you
– Rovann Linhalis
I usually schedule after two days to give more time to other people to answer :)
– gato
Hmmmmm blz, I was even surprised by your score, usually the beginners who don’t score. But blz, good practice. Vlw
– Rovann Linhalis