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

add nodes

上级 6410ca99
{
"node_id": "mysql-8e971f3c569a4e56bb83b5d75a2a425f",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
第一章
第二章
第三章
\ No newline at end of file
{
"node_id": "mysql-925f9d57c7794e5391fb790bcdbf43c6",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "client.md",
"notebook_enable": false,
"exercise_id": "06e56f7cc7fd45b89f1032bd28d6ee5a"
}
\ No newline at end of file
# 连接 PostgreSQL 数据库
下列选项中,可以用于连接到PostgreSQL数据库的有:
## 答案
全部都可以
## 选项
### A
命令行工具 psql
### B
GUI 工具 PgAdmin
### C
JDBC 库 `org.postgresql:postgresql`
### D
Python DBAPI 实现 psycopg2
### E
Go 语言驱动库 PQ。
{
"node_id": "mysql-86367300e7b643e18caf7b9349ab705a",
"keywords": [
"server",
"client",
"数据库服务器",
"数据库客户端"
],
"children": [],
"export": [
"client.json",
"server.json"
],
"keywords_must": [
"服务器",
"客户端"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "server.md",
"notebook_enable": false,
"exercise_id": "297b2eb8c0b740dfb1ba52cd02044fd5"
}
\ No newline at end of file
# PostgreSQL 服务器
关于 PostgreSQL 服务器,以下说法错误的是:
## 答案
PostgreSQL 的服务器和客户端必须运行在不同的计算机上。
## 选项
### A
PostgreSQL 的每个活跃连接对应一个 worker 进程。
### B
PostgreSQL 的服务器将数据存储在一个 owner 为 postgres 的目录下。
### C
PostgreSQL 可以设置监听端口、地址和最大连接数
### D
PostgreSQL 的超级用户默认为 postgres
### E
PostgreSQL 可以运行在 FreeBSD、Linux或Windows系统。
{
"node_id": "mysql-635d4c57d06a4e1abaecbd03d9f5e1ba",
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
第四章
第五章
第六章
\ No newline at end of file
{
"node_id": "mysql-5720037d32894078aa03106e4d798984",
"keywords": [
"login",
"connect"
],
"children": [],
"export": [
"develop.json"
],
"keywords_must": [
"使用",
"基本用法",
"入门"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "develop.md",
"notebook_enable": false,
"exercise_id": "a13e3981d5e94b38bb3ee6a5a909c7cf"
}
\ No newline at end of file
# 开发环境中的 PostgreSQL
你是 SmartMarket 公司的一名开发人员,公司使用 Linux 运行 PostgreSQL 服务,而你的开发机使用 MacOS。下列说法正确的是:
1. 在 MacOS 上,使用 Homebrew 安装 PostgreSQL 后,在当前用户下执行 psql postgres 可以登入数据库
2. 在 Linux 上,使用 yum 或 apt 安装 PostgreSQL 后,sudo su postgres 切换到 postgres 用户,可以执行 psql 登入数据库
3. 对于自己安装的数据库服务器(非RDS),如果需要开放远程登录,需要编辑数据目录下的 postgresql.conf 和 pg_hua.conf
4. 安装 PostgreSQL 前,需要重装系统以获得一个干净的内核环境
5. 安装 PostgreSQL 前,需要手工建立一个名为 postgres 的超级用户
6. 安装 PostgreSQL 需要先安装 gcc 或 llvm clang
7. 对于使用 linux 的开发者,通常需要安装 postgresql 的开发包,这通常可以在主流的 linux 发行版的软件服务中找到,一般叫 postgresql-devel 或 postgresql-dev
## 答案
1, 2, 3, 7
## 选项
### A
1, 2, 3, 4, 5, 6, 7
### B
1, 2, 3
### C
2, 3, 4, 5
### D
5, 6, 7
### E
1, 3, 5, 7
### F
2, 4, 6
{
"node_id": "mysql-79f255c8025d4379b9782e445d37b8b5",
"keywords": [
"sql",
"psql",
" 数据库客户端"
],
"children": [],
"export": [
"psql.json"
],
"keywords_must": [
"psql"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "psql.md",
"notebook_enable": false,
"exercise_id": "6a216c26da85435e9b6cf41f7f209edb"
}
\ No newline at end of file
# PSQL 命令行
关于 PSQL 命令行,以下说法正确的是:
1. psql 命令行内置在 postgresql 安装包中
2. psql 命令行默认以系统当前用户身份登录本机,连接用户同名数据库
3. 进入 psql 命令行,可以使用 `\?` 查看内置的快捷指令
4. 在 psql 命令行中,可以通过 `\!` 在服务端执行shell命令
5. psql 命令行必须以 postgres 用户身份执行
6. psql 命令行必须以 root 用户身份执行
7. psql 只能用于 linux 和 bsd 系统
8. 在 psql 中执行 `\d` 可以查看 relations 列表,即用户表和视图
9. 在 psql 中执行 `\l` 可以查看数据库列表
10. 在 psql 中执行 `\d 表名` 可以查看指定表或视图的详细信息
11. 在 psql 中执行 `\timing` 可以开关查询计时
12. `analyze 表名;``explain 查询;` 以及 `explain analyze 查询;` 都是 psql 特有的命令
## 答案
1, 2, 3, 4, 8, 9, 10, 11
## 选项
### A
全部都对
### B
1, 2, 3, 4, 5, 6
### C
2, 3, 4, 5, 6, 7, 8, 9
### D
全部都错
### E
9, 10, 11, 12
### F
5, 6, 7, 8, 9, 10, 11, 12
### G
5, 6, 7, 12
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "basic.md",
"notebook_enable": false,
"exercise_id": "48b5a5d7529c452696861d9ec6dbc180"
}
\ No newline at end of file
# 基本语法
下列 SQL 语句,哪一项不合法?
## 答案
```postgresql
from test select abc;
```
## 选项
### A
```postgresql
select 3.14;
```
### B
```postgresql
select * from employee;
```
### C
```postgresql
select * from employee where dept = 'hr';
```
### D
```postgresql
select id, name, dept, salary from employee where salary > 10000::money;
```
### E
```postgresql
select now();
```
{
"node_id": "mysql-b1416d413b75470697201b9d6ffeebff",
"keywords": [
"语法",
"select"
],
"children": [],
"export": [
"basic.json"
],
"keywords_must": [
"语法",
"SQL"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "mysql-1557b617893243cc840aa512d312d3f1",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "concept.md",
"notebook_enable": false,
"exercise_id": "3bae822bb4204ae0a001191afec48a58"
}
\ No newline at end of file
# 基本概念
下列叙述中,正确的是
1. 带有 select 关键字的查询不会修改数据
2. 查询表需要 select 权限
3. 修改一个数据库表或对象的结构,通常语句中会出现 create、add、drop、alter 等关键字
4. 修改数据内容,通常会出现update、insert、delete等关键字
5. update、insert、delete可以单独授权
## 答案
2, 3, 4, 5
## 选项
### A
1, 2, 3, 4, 5
### B
4, 5
### C
1, 2, 3
### D
3, 4, 5
\ No newline at end of file
{
"node_id": "mysql-d62d60e24fe14f049712c9db8cf25ea9",
"keywords": [
"DML",
"insert",
"update",
"delete"
],
"children": [],
"export": [
"insert.json",
"update.json",
"delete.json",
"concept.json"
],
"keywords_must": [
"DML",
"DDL",
"insert",
"update",
"delete"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "delete.md",
"notebook_enable": false,
"exercise_id": "fda0d0bd37e342cd8680569a514114f9"
}
\ No newline at end of file
# 删除
SmartMarket 公司的业务数据库中,有一个 orders 表,其结构主要是以下形态:
```postgresql
create table orders
(
id serial primary key,
meta jsonb default '{}'::jsonb,
content jsonb default '{}'::jsonb,
created_at timestamp default now(),
deal boolean
)
```
有一个业务系统会实时的将已经成交(deal 字段为 true)的订单数据转储,现在我们仅需要一个清理 程序,将已经成 交的数据从 orders 表删除并记录被删除的数据id。下面哪个操作是对的?
## 答案
在一个独立的定时任务中执行
```postgresql
delete
from orders
where deal
returning id;
```
并记录id
## 选项
### A
在一个独立的定时任务中执行
```postgresql
truncate orders;
```
### B
在一个独立的定时任务中执行
```postgresql
delete
from orders;
```
### C
在一个独立的定时任务中执行
```postgresql
drop table orders;
create table orders
(
id serial primary key,
meta jsonb default '{}'::jsonb,
content jsonb default '{}'::jsonb,
created_at timestamp default now(),
deal boolean
);
```
### D
建立视图
```postgresql
create view order_view as
select id, meta, content, created_at
from orders
where not deal;
```
并要求业务系统只能访问这个视图。
### E
在一个独立的定时任务中执行
```postgresql
delete
from orders
where deal;
```
并记录操作前后表中的最大 id
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "insert.md",
"notebook_enable": false,
"exercise_id": "27973a87da2c4213b4a1b26897385854"
}
\ No newline at end of file
# 插入
现有一个表:
```postgresql
create table book(
id serial primary key ,
title text not null ,
meta jsonb default '{}'::jsonb,
price money,
isbn text not null ,
publish_at date not null
);
create unique index on book(isbn);
create index on book using gin(meta);
```
那么下列哪个选项的代码可以执行成功?
## 答案
```postgresql
insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date;
insert into book(title, price, isbn, publish_at) select 'a other book title', 25.4, 'yy-yyyy-xxxx', '2019-12-1'::date;
```
## 选项
### 唯一键冲突
```postgresql
insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date;
insert into book(title, price, isbn, publish_at) select 'a other book title', 35.4, 'xx-xxxx-xxxx', '2019-12-1'::date;
```
### 缺少必要的列
```postgresql
insert into book(price, isbn, publish_at) select 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date;
insert into book(price, isbn, publish_at) select 35.4, 'yy-yyyy-xxxx', '2019-12-1'::date;
```
### 类型错误
```postgresql
insert into book(title, price, isbn, publish_at) select 'a book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date;
insert into book(title, price, isbn, publish_at) select 'a other book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date;
```
### 违反非空约束
```postgresql
insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date;
insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date;
```
{
"type": "code_options",
"author": "ccat",
"source": "update.md",
"notebook_enable": false,
"exercise_id": "7ac9fc0f4d3046788db2a0322a78ff68"
}
\ No newline at end of file
# 更新数据
现有 employee 表如下:
```postgresql
create table employee
(
id serial primary key,
name text,
dept text,
salary money
);
```
我们希望修改销售部(dept 字段为 sale)员工 Dora Muk 的工资,将其增加 1000,返回她的工号。正确的修改语句是:
## 答案
```postgresql
update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk' returning id;
```
## 选项
### 过滤条件不严谨
```postgresql
update employee set salary = salary + 1000 where name = 'Dora Muk' returning id;
```
### 没有返回员工id
```postgresql
update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk';
```
### 缺少过滤条件
```postgresql
update employee set salary = salary + 1000 returning id;
```
### 错误的赋值语句
```postgresql
update employee set salary += 1000 returning id;
```
{
"node_id": "mysql-cd45ce715f914ef2895df639a5d206a3",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-426b0b1e04a4462e984ee77ca536f916",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
8.1.1
8.1.2
\ No newline at end of file
{
"node_id": "mysql-1418d1a710ab4e7c8cacb0bad047179e",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-7256fe88bcf241d486c9e2e254ef66d9",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-27ff66e31d3d4118977cbbc04da6887e",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-ec8f22f2c63a4f27bd12815644d0f3db",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-ce5531c7c7934e2d9be844133f103fee",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
第九章
\ No newline at end of file
{
"node_id": "mysql-fcca525ab0f04f16834ded9b2b3f38a4",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-2eb9e9d351e848f580b70cf9e7b93280",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-3cae643e21644d6d937d69b59014922f",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-8ee645083a5b4062b2c09b2a14a06f67",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
12.1
12.4
\ No newline at end of file
{
"node_id": "mysql-f5527eae7f3148108c92ff99a6d4ed4a",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-91cc9c73e58945d3ba654370a057a1c7",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-aabf6529eaa04d94b627de1a5f2fea23",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
13.2
\ No newline at end of file
第十五章
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册