Files
mysql-press/docs/mysql/delete.md
2021-05-08 11:03:38 +08:00

49 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 删除数据
> mysql删除是使用delete语句
## delete
删除语法其实是非常简单的,但是也是比较危险的,需要慎重操作。
```sql
delete from table [where ];
```
最简单的删除语句是
```sql
delete from tablename;
```
但是不要这么操作,他会像修改时候一样,全部删除掉,所以操作删除的时候一定要添加条件
```sql
delete from tablename where ;
```
还是之前的class表。
![图 1](../../images/c486c8a54c50d5f9eb96c1e14ba76b5b069fe4055c8eb57f0a5c2d9a945639bc.png)
比如我要删除姓名为张三的人,应该怎么删除呢?
```sql
delete from class where name = "张三";
```
![图 2](../../images/60aac5dbd2c221fcb19925284ebd621b59a08ac3d88115a8572a294483e85992.png)
删除成功了,然后查询之后张三就没有了。
比如要删除年龄是18的人那么应该就是 `where age = 18`
```sql
delete from class where age = 18;
```
![图 3](../../images/78eb44abb4fa3770f2ca3f9f064f8e6846e3b21f28044ce872f880346d438776.png)
成功删除了删除了所有年龄是18的人。
删除是比较简单的操作,接下来就要来看一下主键。