2014-12-10 08:06:36 +01:00
|
|
|
CREATE TABLE t1(id INT);
|
|
|
|
CREATE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 WHERE id>10;
|
|
|
|
INSERT INTO t1 VALUES (5), (8), (10), (20), (30);
|
|
|
|
SELECT * FROM t1;
|
|
|
|
id
|
|
|
|
5
|
|
|
|
8
|
|
|
|
10
|
|
|
|
20
|
|
|
|
30
|
|
|
|
SELECT * FROM v1;
|
|
|
|
id
|
|
|
|
20
|
|
|
|
30
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1 WHERE id>11;
|
|
|
|
ERROR 42S01: Table 'v1' already exists
|
|
|
|
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME='v1';
|
|
|
|
VIEW_DEFINITION
|
2016-11-27 19:50:10 +01:00
|
|
|
select `test`.`t1`.`id` AS `id` from `test`.`t1` where `test`.`t1`.`id` > 10
|
2014-12-10 08:06:36 +01:00
|
|
|
CREATE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 WHERE id>12;
|
|
|
|
Warnings:
|
2015-04-13 20:36:49 +02:00
|
|
|
Note 1050 Table 'v1' already exists
|
2014-12-10 08:06:36 +01:00
|
|
|
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME='v1';
|
|
|
|
VIEW_DEFINITION
|
2016-11-27 19:50:10 +01:00
|
|
|
select `test`.`t1`.`id` AS `id` from `test`.`t1` where `test`.`t1`.`id` > 10
|
2014-12-10 08:06:36 +01:00
|
|
|
CREATE OR REPLACE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 WHERE id>13;
|
|
|
|
ERROR HY000: Incorrect usage of OR REPLACE and IF NOT EXISTS
|
|
|
|
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME='v1';
|
|
|
|
VIEW_DEFINITION
|
2016-11-27 19:50:10 +01:00
|
|
|
select `test`.`t1`.`id` AS `id` from `test`.`t1` where `test`.`t1`.`id` > 10
|
2014-12-10 08:06:36 +01:00
|
|
|
CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1 WHERE id>14;
|
|
|
|
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME='v1';
|
|
|
|
VIEW_DEFINITION
|
2016-11-27 19:50:10 +01:00
|
|
|
select `test`.`t1`.`id` AS `id` from `test`.`t1` where `test`.`t1`.`id` > 14
|
2014-12-10 08:06:36 +01:00
|
|
|
INSERT INTO t1 VALUES (50), (80), (3), (2), (40);
|
|
|
|
SELECT * FROM t1;
|
|
|
|
id
|
|
|
|
5
|
|
|
|
8
|
|
|
|
10
|
|
|
|
20
|
|
|
|
30
|
|
|
|
50
|
|
|
|
80
|
|
|
|
3
|
|
|
|
2
|
|
|
|
40
|
|
|
|
SELECT * FROM v1;
|
|
|
|
id
|
|
|
|
20
|
|
|
|
30
|
|
|
|
50
|
|
|
|
80
|
|
|
|
40
|
2020-06-01 22:27:14 +02:00
|
|
|
DROP TABLE IF EXISTS v1;
|
|
|
|
Warnings:
|
2020-06-05 17:55:11 +02:00
|
|
|
Note 1965 'test.v1' is a view
|
2014-12-10 08:06:36 +01:00
|
|
|
DROP VIEW IF EXISTS v1;
|
|
|
|
DROP VIEW IF EXISTS v1;
|
|
|
|
Warnings:
|
2017-12-12 08:35:18 +01:00
|
|
|
Note 4092 Unknown VIEW: 'test.v1'
|
2020-06-01 22:27:14 +02:00
|
|
|
DROP VIEW IF EXISTS t1;
|
|
|
|
Warnings:
|
2020-06-05 11:51:01 +02:00
|
|
|
Warning 1347 'test.t1' is not of type 'VIEW'
|
2020-06-01 22:27:14 +02:00
|
|
|
Note 4092 Unknown VIEW: 'test.t1'
|
2014-12-10 08:06:36 +01:00
|
|
|
DROP TABLE t1;
|