提交 fb707b87 编写于 作者: M Mars Liu

view

上级 6dfa31b8
......@@ -3,5 +3,5 @@
"author": "ccat",
"source": "union.md",
"notebook_enable": false,
"exercise_id": "331f369b150340f9989ccea8abfcd42f"
"exercise_id": "7c8ecf1329e64616a56e5def05d52c6c"
}
\ No newline at end of file
......@@ -2,7 +2,9 @@
"node_id": "mysql-95a29a6a448849029d548393bbdf283e",
"keywords": [],
"children": [],
"export": [],
"export": [
"view.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "Mars Liu",
"source": "view.md",
"notebook_enable": false,
"exercise_id": "5335391d25d0428aa3dbe1759ac1ef37"
}
\ No newline at end of file
# 视图
关于 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
```
{
"node_id": "mysql-9339ebb389474492a0ba2c2ff29e78fb",
"keywords": ["create view"],
"keywords": [
"create view"
],
"children": [],
"export": [],
"export": [
"create_view.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "Mars Liu",
"source": "create_view.md",
"notebook_enable": false,
"exercise_id": "990e457f98db463b9fe14831f6ab2afc"
}
\ No newline at end of file
# 创建视图
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;
```
{
"type": "code_options",
"author": "Mars Liu",
"source": "alter_view.md",
"notebook_enable": false,
"exercise_id": "a54d8dc829b64c78b63f3480af42e80e"
}
\ No newline at end of file
# 修改视图
针对用户表和员工表:
```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
......@@ -2,7 +2,9 @@
"node_id": "mysql-3a51b0740b704d92a534335a7a8dfd6e",
"keywords": [],
"children": [],
"export": [],
"export": [
"alter_view.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"node_id": "mysql-9e6db7d333c348c99d943774664792a7",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
......@@ -2,7 +2,9 @@
"node_id": "mysql-36171582b8324dc98ff16d9b0cac406d",
"keywords": [],
"children": [],
"export": [],
"export": [
"drop_view.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "Mars Liu",
"source": "drop_view.md",
"notebook_enable": false,
"exercise_id": "3ef595b611414ae7957ffa93a91a5b99"
}
\ No newline at end of file
# 删除视图
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
{
"node_id": "mysql-caf587fff11a43069351e61c98442dd1",
"keywords": ["update", "view"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
......@@ -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
......@@ -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": []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册