1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| DROP DATABASE IF EXISTS `ridb` ; CREATE DATABASE IF NOT EXISTS `ridb`; USE `ridb` ; CREATE TABLE `mechanic` ( `id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE = InnoDB; CREATE TABLE `gunpla` ( `id` INT NOT NULL AUTO_INCREMENT, `mid` INT, `grade` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`mid`) REFERENCES `mechanic` (`id`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE = InnoDB; INSERT INTO mechanic (id, name) VALUES (1, 'Gundam'), (2, 'Gun Cannon'), (3, 'Gun Tank'); INSERT INTO gunpla (id, mid, grade) VALUES (1, 1, 'MG'), (2, 2, 'SD'), (3, 3, 'HGUC'); select * from gunpla; delete from mechanic where name='Gundam'; select * from gunpla;
|