mysql DROP TABLE IF EXISTS product mysql CREATE TABLE product id INT U

 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
48
49
50
51
52
53
54
55
56
57
58
59
mysql> DROP TABLE IF EXISTS product;
mysql> CREATE TABLE product
-> (
-> id INT UNSIGNED NOT NULL AUTO_INCREMENT,
-> title VARCHAR(70) NOT NULL DEFAULT '',
-> price FLOAT NOT NULL DEFAULT 0,
-> quo FLOAT NOT NULL DEFAULT 0,
-> PRIMARY KEY (id)
-> );
mysql> INSERT INTO product
-> VALUES
-> (1, 'Товар 1', 123, 200),
-> (2, 'Товар 2', 150, 200),
-> (3, 'Товар 3', 187, 300),
-> (4, 'Товар 4', 300, 400),
-> (5, 'Товар 5', 225, 500);
mysql> DROP VIEW IF EXISTS product_with_tax;
mysql> CREATE
-> DEFINER='root'@'localhost'
-> SQL SECURITY DEFINER
-> VIEW product_with_tax AS
-> SELECT *, price * 1.18 AS price_tax
-> FROM product
-> WHERE quo > 0;
mysql> SELECT * FROM product_with_tax;
mysql> DROP VIEW IF EXISTS completeOrders;
mysql> CREATE VIEW completeOrders AS
-> SELECT idorder, time, status
-> FROM `order`
-> WHERE status = 'выполнен'
-> \g
mysql> SELECT * FROM completeOrders;
mysql> SHOW CREATE VIEW completeOrders;
mysql> DROP VIEW IF EXISTS books_piter;
mysql> CREATE VIEW books_piter AS
-> SELECT id, title, author, cover
-> FROM books
-> WHERE publisher = 'Питер';
mysql> SELECT * FROM books_piter;
create view vAsia as select country.Name from country where country.Continent = 'Asia';
mysql> select * from vAsia;
create view vEurope as select country.Name from country where country.Continent = 'Europe';
mysql> select * from vEurope;
create view vAfrica as select country.Name from country where country.Continent = 'Africa';
mysql> select * from vAfrica;