· 8 years ago · Jan 22, 2018, 10:28 PM
1DROP TABLE IF EXISTS t1;
2CREATE TABLE IF NOT EXISTS t1 (
3 id tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT,
4 t2_id tinyint(3) UNSIGNED DEFAULT NULL,
5 col3 varchar(255) NOT NULL,
6 PRIMARY KEY (id)
7) ENGINE=InnoDB DEFAULT CHARSET=utf8;
8
9INSERT INTO t1 (id, t2_id, col3) VALUES
10(1, 1, 'a'),
11(2, 1, 'b'),
12(3, 2, '3'),
13(4, 2, '7'),
14(5, NULL, '!');
15
16DROP TABLE IF EXISTS t2;
17CREATE TABLE IF NOT EXISTS t2 (
18 id tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT,
19 col2 varchar(255) NOT NULL,
20 PRIMARY KEY (id)
21) ENGINE=InnoDB DEFAULT CHARSET=utf8;
22
23INSERT INTO t2 (id, col2) VALUES
24(1, 'Character'),
25(2, 'Number');
26
27CREATE OR REPLACE
28VIEW v_t1_details
29AS SELECT t1.id, t2.col2, t1.col3
30FROM t1
31LEFT JOIN t2 ON t1.t2_id = t2.id;
32
33UPDATE v_t1_details SET col3 = 'c' WHERE id = 2;
34
35#1288 - The target table v_t1_details of the UPDATE is not updatable