blob: a90f3e27ab707f9ce67b41bd0415886cdc554d14 (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
connection node_2;
connection node_1;
CREATE TABLE author (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL
) ENGINE = InnoDB;
CREATE TABLE book (
id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(200) NOT NULL,
author_id SMALLINT UNSIGNED NOT NULL,
CONSTRAINT `fk_book_author`
FOREIGN KEY (author_id) REFERENCES author (id)
ON DELETE CASCADE
ON UPDATE RESTRICT
) ENGINE = InnoDB;
INSERT INTO author (name) VALUES ('Abdul Alhazred');
INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID());
TRUNCATE TABLE book;
SELECT * FROM author;
id name
1 Abdul Alhazred
SELECT * FROM book;
id title author_id
connection node_2;
SELECT * FROM author;
id name
1 Abdul Alhazred
SELECT * FROM book;
id title author_id
INSERT INTO author (name) VALUES ('Abdul Alhazred');
INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID());
TRUNCATE TABLE book;
SELECT * FROM author;
id name
1 Abdul Alhazred
2 Abdul Alhazred
SELECT * FROM book;
id title author_id
connection node_1;
TRUNCATE TABLE book;
SELECT * FROM author;
id name
1 Abdul Alhazred
2 Abdul Alhazred
SELECT * FROM book;
id title author_id
DROP TABLE book, author;
|