update.md 856 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8
# 更新数据

现有 employee 表如下:

```mysql
create table employee
(
    id serial primary key,
M
Mars Liu 已提交
9 10 11
    name varchar(64),
    dept varchar(64),
    salary decimal(12, 4)
M
Mars Liu 已提交
12 13 14 15 16
);
```

Joe 希望修改销售部(dept 字段为 sale)员工 Dora Muk 的工资,将其增加 1000。正确的修改语句是:

M
Mars Liu 已提交
17 18
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill)

M
Mars Liu 已提交
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
## 答案

```mysql
update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk';
```

## 选项

### 过滤条件不严谨

```mysql
update employee set salary = salary + 1000 where name = 'Dora Muk';
```


### 缺少过滤条件

```mysql
update employee set salary = salary + 1000;
```

### 错误的赋值语句

```mysql
update employee set salary += 1000;
```