diff --git "a/data/2.MySQL\344\270\255\351\230\266/2. \346\237\245\350\257\242/6.UNION/union.json" "b/data/2.MySQL\344\270\255\351\230\266/2. \346\237\245\350\257\242/6.UNION/union.json" index b71330f7f4380a3e215b34936ded3e8f3e9d0d9c..9d37523b3cf9ad15fb64ab0862be383ea5589864 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2. \346\237\245\350\257\242/6.UNION/union.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/2. \346\237\245\350\257\242/6.UNION/union.json" @@ -3,5 +3,5 @@ "author": "ccat", "source": "union.md", "notebook_enable": false, - "exercise_id": "331f369b150340f9989ccea8abfcd42f" + "exercise_id": "7c8ecf1329e64616a56e5def05d52c6c" } \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/config.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/config.json" index ed1089c486fd6964077e50682cb4f4609d6b0017..47c1c42ddfc7ebc04bfc9f272801289bb3514b93 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/config.json" @@ -2,7 +2,9 @@ "node_id": "mysql-95a29a6a448849029d548393bbdf283e", "keywords": [], "children": [], - "export": [], + "export": [ + "view.json" + ], "keywords_must": [], "keywords_forbid": [], "group": 0 diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/view.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/view.json" new file mode 100644 index 0000000000000000000000000000000000000000..81f3e0164dc1a9e560fcd4688bafad84df5f0974 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/view.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "Mars Liu", + "source": "view.md", + "notebook_enable": false, + "exercise_id": "5335391d25d0428aa3dbe1759ac1ef37" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/view.md" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/view.md" new file mode 100644 index 0000000000000000000000000000000000000000..153e40d106ee302ef340fac0dd06d764649541dc --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/1.\350\247\206\345\233\276\347\232\204\345\237\272\346\234\254\346\246\202\345\277\265/view.md" @@ -0,0 +1,54 @@ +# 视图 + +关于 MySQL 的视图,以下哪些说法是正确的? + +1. 视图可以看作预处理的查询 +2. 视图可以作为表用在查询中 +3. 包含主键的视图可以更新 +4. 与源数据满足一一对应关系的视图可以更新 +5. 包含列子查询的视图不能更新 +6. 包含 distinct 的视图不能更新 +7. 包含 union 或 union all 的视图不能更新 +8. 可以给用户授予指定视图的 show view 权限,以控制其访问 + +## 答案 + +所有都对 + +## 选项 + +### A + +所有都不对 + +### B + +``` +1, 2, 3, 4, 5 +``` + +### C + +``` +2, 3, 4, 5, 6, 7, 8 +``` + +### D + +``` +1, 3, 5, 7 +``` + + +### E + +``` +5, 6, 7, 8 +``` + +### F + +``` +4, 5, 7 +``` + diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/config.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/config.json" index e11bcf9f5f2ffea27bfeb95a9db96bfc8bd5be51..7c4135a8298f2a4a316cc8ce51468b073fcda8ea 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/config.json" @@ -1,8 +1,12 @@ { "node_id": "mysql-9339ebb389474492a0ba2c2ff29e78fb", - "keywords": ["create view"], + "keywords": [ + "create view" + ], "children": [], - "export": [], + "export": [ + "create_view.json" + ], "keywords_must": [], "keywords_forbid": [], "group": 0 diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/create_view.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/create_view.json" new file mode 100644 index 0000000000000000000000000000000000000000..710b185573c661c680a20e66d67a8fc67d37f67e --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/create_view.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "Mars Liu", + "source": "create_view.md", + "notebook_enable": false, + "exercise_id": "990e457f98db463b9fe14831f6ab2afc" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/create_view.md" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/create_view.md" new file mode 100644 index 0000000000000000000000000000000000000000..ecf523d828454befa54d056f479b1cc2e44a1275 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/2. \345\210\233\345\273\272\350\247\206\345\233\276/create_view.md" @@ -0,0 +1,71 @@ +# 创建视图 + +Joe 想要基于 + +```mysql +create table employee( + id int primary key auto_increment, + name varchar(256), + address varchar(1024), + dept varchar(64) + -- ignore more +); + +create table customer( + id int primary key auto_increment, + name varchar(256), + address varchar(1024), + level int + -- ignore more +) +``` + +创建视图 v_addresses,包含写姓名和地址两列。下列哪个正确? + +## 答案 + +```mysql +create view v_addresses as + select name, address from employee + union + select name, address from customer; +``` + +## 选项 + +### A + +```mysql +create view v_addresses as + select * from employee + union + select * from customer; +``` + +### B + +```mysql +create view v_addresses as + select name, address from employee + union + select name, address from customer; +``` + +### C + +```mysql +create view v_addresses as +begin; + select name, address from employee + select name, address from customer; +end; +``` + +### D + +```mysql +create view v_addresses + select name, address from employee + union + select name, address from customer; +``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/alter_view.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/alter_view.json" new file mode 100644 index 0000000000000000000000000000000000000000..1742f0fddeb0bf769582d8619c828cf530b82320 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/alter_view.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "Mars Liu", + "source": "alter_view.md", + "notebook_enable": false, + "exercise_id": "a54d8dc829b64c78b63f3480af42e80e" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/alter_view.md" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/alter_view.md" new file mode 100644 index 0000000000000000000000000000000000000000..6ec1ae1d3f7a51a672c255a7a15b726d888498fa --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/alter_view.md" @@ -0,0 +1,76 @@ +# 修改视图 + +针对用户表和员工表: + +```mysql +create table employee( + id int primary key auto_increment, + name varchar(256), + address varchar(1024), + dept varchar(64) + -- ignore more +); + +create table customer( + id int primary key auto_increment, + name varchar(256), + address varchar(1024), + level int + -- ignore more +) +``` + +Joe 建立了联系人视图: + +```mysql +create view v_contacts as + select name, address from employee + union + select name, address from customer; +``` + +现在,他想要加入一列 catalog ,区分员工和顾客,下面哪一个做法是错的? + + +## 答案 + +```mysql +create if not exists view v_contacts as + select name, address, 'employee' as catalog from employee + union + select name, address, 'customer' as catalog from customer; +``` + +## 选项 + +## A + +```mysql +alter view v_contacts as + select name, address, 'employee' as catalog from employee + union + select name, address, 'customer' as catalog from customer; + +``` + + +### B + +```mysql +create or replace view v_contacts as + select name, address, 'employee' as catalog from employee + union + select name, address, 'customer' as catalog from customer; + +``` + +### C + +```mysql +drop view v_contacts; +create view v_contacts as + select name, address, 'employee' as catalog from employee + union + select name, address, 'customer' as catalog from customer; + +``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \344\277\256\346\224\271\350\247\206\345\233\276/config.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/config.json" similarity index 78% rename from "data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \344\277\256\346\224\271\350\247\206\345\233\276/config.json" rename to "data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/config.json" index a7bb70f2a8a0e02cad4e85ad12acdb3985e6894e..1b5a98319f2d1ec6dbf339bb7a3c95f55333ec2c 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \344\277\256\346\224\271\350\247\206\345\233\276/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3. \344\277\256\346\224\271\350\247\206\345\233\276/config.json" @@ -2,7 +2,9 @@ "node_id": "mysql-3a51b0740b704d92a534335a7a8dfd6e", "keywords": [], "children": [], - "export": [], + "export": [ + "alter_view.json" + ], "keywords_must": [], "keywords_forbid": [], "group": 0 diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3.\347\211\251\345\214\226\350\247\206\345\233\276/config.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3.\347\211\251\345\214\226\350\247\206\345\233\276/config.json" deleted file mode 100644 index 7111526574b7f6b26d2c68155814ad895d33734f..0000000000000000000000000000000000000000 --- "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/3.\347\211\251\345\214\226\350\247\206\345\233\276/config.json" +++ /dev/null @@ -1,9 +0,0 @@ -{ - "node_id": "mysql-9e6db7d333c348c99d943774664792a7", - "keywords": [], - "children": [], - "export": [], - "keywords_must": [], - "keywords_forbid": [], - "group": 0 -} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/6. \345\210\240\351\231\244\350\247\206\345\233\276/config.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/config.json" similarity index 78% rename from "data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/6. \345\210\240\351\231\244\350\247\206\345\233\276/config.json" rename to "data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/config.json" index 6ee254ca847408f4c28ceba9d274a89a3c458b5c..36974efaa6770638e6740e3d5f9e934e9584a9fd 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/6. \345\210\240\351\231\244\350\247\206\345\233\276/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/config.json" @@ -2,7 +2,9 @@ "node_id": "mysql-36171582b8324dc98ff16d9b0cac406d", "keywords": [], "children": [], - "export": [], + "export": [ + "drop_view.json" + ], "keywords_must": [], "keywords_forbid": [], "group": 0 diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/drop_view.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/drop_view.json" new file mode 100644 index 0000000000000000000000000000000000000000..b34230aec54a007079c3cd5b886db35f7d2ca1ce --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/drop_view.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "Mars Liu", + "source": "drop_view.md", + "notebook_enable": false, + "exercise_id": "3ef595b611414ae7957ffa93a91a5b99" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/drop_view.md" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/drop_view.md" new file mode 100644 index 0000000000000000000000000000000000000000..993e87d12976beeb58953a9a50aa1921cbcbc8e7 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/4. \345\210\240\351\231\244\350\247\206\345\233\276/drop_view.md" @@ -0,0 +1,41 @@ +# 删除视图 + + +Joe 建立了联系人视图: + +```mysql +create view v_contacts as + select name, address from employee + union + select name, address from customer; +``` + +现在,他完成了相关工作,想要删掉这个视图,应该执行哪个操作? + + +## 答案 + +```mysql +drop view v_contacts; +``` + +## 选项 + +## A + +```mysql +delete from v_contacts; +``` + + +### B + +```mysql +delete from v_contacts where 1=1; +``` + +### C + +```mysql +truncate table v_contacts; +``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/5. \346\233\264\346\226\260\350\247\206\345\233\276\346\225\260\346\215\256/config.json" "b/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/5. \346\233\264\346\226\260\350\247\206\345\233\276\346\225\260\346\215\256/config.json" deleted file mode 100644 index 75b7d1044cc789bce3cd5ccfeab25280d085ba95..0000000000000000000000000000000000000000 --- "a/data/2.MySQL\344\270\255\351\230\266/7.\350\247\206\345\233\276/5. \346\233\264\346\226\260\350\247\206\345\233\276\346\225\260\346\215\256/config.json" +++ /dev/null @@ -1,9 +0,0 @@ -{ - "node_id": "mysql-caf587fff11a43069351e61c98442dd1", - "keywords": ["update", "view"], - "children": [], - "export": [], - "keywords_must": [], - "keywords_forbid": [], - "group": 0 -} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.Double Not Exists/DoubleNotExists.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.Double Not Exists/DoubleNotExists.json" index 3712b3980b566431300c8f507ecda4f52f11489e..2ff42de6a7f95a72b9348138f95ddae436ecaaba 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.Double Not Exists/DoubleNotExists.json" +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.Double Not Exists/DoubleNotExists.json" @@ -3,5 +3,5 @@ "author": "Mars Liu", "source": "DoubleNotExists.md", "notebook_enable": false, - "exercise_id": "2fabb69f22224e48a26fec8911798ceb" + "exercise_id": "b9381a1d56da4de0862f5a8d3c7bb59a" } \ No newline at end of file diff --git a/data/tree.json b/data/tree.json index fe512493837f47384bd6926d1da5a42b18263016..31955517f605435fe9a1f8075e419dc29cbccea1 100644 --- a/data/tree.json +++ b/data/tree.json @@ -509,7 +509,11 @@ { "存储引擎": { "node_id": "mysql-af89d54d66974111b4f67aeba2af7161", - "keywords": [], + "keywords": [ + "engine", + "innodb", + "myisam" + ], "children": [], "keywords_must": [], "keywords_forbid": [] @@ -582,7 +586,9 @@ { "UNION": { "node_id": "mysql-b57b6c08f5f240c6a997284e4448f088", - "keywords": [], + "keywords": [ + "union" + ], "children": [], "keywords_must": [], "keywords_forbid": [] @@ -923,15 +929,6 @@ "keywords_forbid": [] } }, - { - "物化视图": { - "node_id": "mysql-9e6db7d333c348c99d943774664792a7", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [] - } - }, { " 修改视图": { "node_id": "mysql-3a51b0740b704d92a534335a7a8dfd6e", @@ -941,18 +938,6 @@ "keywords_forbid": [] } }, - { - " 更新视图数据": { - "node_id": "mysql-caf587fff11a43069351e61c98442dd1", - "keywords": [ - "update", - "view" - ], - "children": [], - "keywords_must": [], - "keywords_forbid": [] - } - }, { " 删除视图": { "node_id": "mysql-36171582b8324dc98ff16d9b0cac406d", @@ -1612,6 +1597,19 @@ "keywords_forbid": [] } }, + { + "Double Not Exists": { + "node_id": "mysql-72761d60ad7c4a9a9c87435daca246b9", + "keywords": [ + "exists", + "not exists", + "double not exists" + ], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, { "写入和冲突": { "node_id": "mysql-f9f2ae841cf14d079c8433c833d3396d", @@ -1801,7 +1799,10 @@ { "增加中间表": { "node_id": "mysql-a2ddae1b044149ecbb74db3b6eb32721", - "keywords": [], + "keywords": [ + "middle", + "中间表" + ], "children": [], "keywords_must": [], "keywords_forbid": []