1 / 2

Referential Integrity MySQL

Referential Integrity MySQL. CREATE TABLE exmp1( id INT NOT NULL, val TEXT, UNIQUE (id) ) TYPE=InnoDB; CREATE TABLE exmp2( id INT, blah TEXT, INDEX(id), CONSTRAINT id_fkey FOREIGN KEY (id) REFERENCES exmp1(id) ON UPDATE CASCADE ) TYPE=InnoDB;. Examples:Zoo animals.

urania
Download Presentation

Referential Integrity MySQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Referential Integrity MySQL • CREATE TABLE exmp1( id INT NOT NULL, val TEXT, UNIQUE (id) ) TYPE=InnoDB; • CREATE TABLE exmp2( id INT, blah TEXT, INDEX(id), CONSTRAINT id_fkey FOREIGN KEY (id) REFERENCES exmp1(id) ON UPDATE CASCADE ) TYPE=InnoDB;

  2. Examples:Zoo animals • CREATE TABLE species (id TINYINT NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) TYPE=INNODB; • INSERT INTO species VALUES (1, 'orangutan'), (2, 'elephant'), (3, 'hippopotamus'), (4, 'yak'); • CREATE TABLE zoo (id INT(4) NOT NULL, name VARCHAR(50) NOT NULL, FK_species TINYINT(4) NOT NULL, INDEX (FK_species), constraint FOREIGN KEY (FK_species) REFERENCES species (id) on update cascade, PRIMARY KEY(id)) TYPE=INNODB; • INSERT INTO zoo VALUES (1, 'Harry', 5);//error:violate R.I. • INSERT INTO zoo VALUES (1, 'Harry', 2);//OK • Update species set id=5 where name=‘elephant’;//change zoo too

More Related