CREATE TABLE author id int NOT NULL auto_increment name VARCHAR 255 PR

 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
28
29
30
31
32
CREATE TABLE `author`
(
`id` int NOT NULL auto_increment,
`name` VARCHAR(255),
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_bin;
CREATE TABLE `book`
(
`id` int NOT NULL auto_increment,
`name` VARCHAR(255),
`year` INT,
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_bin;
CREATE TABLE `author_book`
(
`author_id` int NOT NULL,
`book_id` int NOT NULL,
CONSTRAINT `author_id_fk` FOREIGN KEY (`author_id`)
REFERENCES `author` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `book_id_fk` FOREIGN KEY (`book_id`)
REFERENCES `book` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_bin;