2014-09-30 18:06:15 -04:00
|
|
|
CREATE TABLE parent (
|
|
|
|
id INT NOT NULL,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
) ENGINE=InnoDB;
|
|
|
|
CREATE TABLE child (
|
|
|
|
id INT,
|
|
|
|
parent_id INT,
|
|
|
|
FOREIGN KEY (parent_id)
|
|
|
|
REFERENCES parent(id)
|
|
|
|
ON UPDATE SET NULL
|
|
|
|
ON DELETE SET NULL
|
|
|
|
) ENGINE=InnoDB;
|
|
|
|
INSERT INTO parent VALUES (1),(2);
|
|
|
|
INSERT INTO child VALUES (1,1),(2,2);
|
2016-05-01 19:10:13 +03:00
|
|
|
connection node_2;
|
2014-09-30 18:06:15 -04:00
|
|
|
DELETE FROM parent WHERE id = 1;
|
|
|
|
SELECT parent_id IS NULL FROM child WHERE id = 1;
|
|
|
|
parent_id IS NULL
|
|
|
|
1
|
2016-05-01 19:10:13 +03:00
|
|
|
connection node_1;
|
2014-09-30 18:06:15 -04:00
|
|
|
SELECT parent_id IS NULL FROM child WHERE id = 1;
|
|
|
|
parent_id IS NULL
|
|
|
|
1
|
|
|
|
UPDATE parent SET id = 3 WHERE id = 2;
|
|
|
|
SELECT parent_id IS NULL FROM child WHERE id = 2;
|
|
|
|
parent_id IS NULL
|
|
|
|
1
|
2016-05-01 19:10:13 +03:00
|
|
|
connection node_2;
|
2014-09-30 18:06:15 -04:00
|
|
|
SELECT parent_id IS NULL FROM child WHERE id = 2;
|
|
|
|
parent_id IS NULL
|
|
|
|
1
|
2016-05-01 19:10:13 +03:00
|
|
|
connection node_1;
|
2014-09-30 18:06:15 -04:00
|
|
|
DROP TABLE child;
|
|
|
|
DROP TABLE parent;
|