update完成

This commit is contained in:
2021-05-06 14:34:12 +08:00
parent 995f1b33c4
commit 9eab97d0a8
9 changed files with 85 additions and 0 deletions

View File

@@ -4,3 +4,88 @@
## 修改数据
修改数据也有自己的另一个语法。
```sql
update table set name=value;
```
上面的语法就是修改数据的最简单的语句,下面来试一下
```sql
update class set age=18;
```
将年龄该表成18这时候就发现问题了现在不知道要修改的是哪一个只是设置了age=18。
先来看一下效果。
![图 8](../../images/9d3e1d0de6565ca112b5e053de55a46569c36c3b898348519ebebb415e10af88.png)
现在的数据是这样的,我们运行修改下。
![图 9](../../images/832e7ea33a2a54dbb0f096e4c16455fffc24b7d9b9353719ead8f1ef659c7d58.png)
成功了,再次查询
![图 10](../../images/7d626527db2a4d933abe9628f2f8a25ff7a0064629c7d37bb85390819ccd9696.png)
所有人的年龄都变成18了我们需要的是改变一个人的而不是改变所有人的那应该怎么做呢
### where
使用where可以添加条件让执行的时候找到对应的行来操作这个怎么使用呢
还是以update为例我们要将张三的年龄改成20岁应该怎么做呢
```sql
update class set age = 20 where name = "张三";
```
这样就可以确定到 `name=张三` 的人where后面跟上 `字段=值` 就可以确定到这个字段等于这个值得行。
让我们来看一下效果
![图 11](../../images/0beea2c7a7195870cceaee9d2abffb125068aafbf9020ef9467cceff2b370019.png)
查询一下
![图 12](../../images/b9fda4e316e75b09f827630421d8bab27e57101ee12769727311de3f34670c2f.png)
只有张三的年龄变成了20其他人的并没有变那么我们将小名的名字变成21就应该知道怎么写了。
```sql
update class set age = 21 where name = "小名";
```
运行一下
![图 14](../../images/bf68e4509145b4add73bd70a99e2c52daed0c0bffc16cb01eaced416f2a2d8be.png)
修改成功了。
### 修改多个字段
上买只是修改了一个字段,那么如何修改多个字段呢?
```sql
update table set name=value,name=value,....;
```
set 后面跟上修改的字段名=值,然后用逗号隔开 `,`
修改一下李四的年龄与性别将性别改成男年龄改成10.
```sql
update class set sex="",age=10 where name="李四";
```
执行一下
![图 15](../../images/bb17eb99a1330e324b3e220d2128ec8c0a354311bc573b25207125e79b73b27f.png)
李四的性别已经变成男了 年龄变成10了。
这就是一次修改多个。
下面将来看一下数据删除

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB