zoukankan      html  css  js  c++  java
  • 20.删除表中的数据

    20.1 实践删除表中的数据

    1、命令语法:delete from <表名> where <表达式> 提示:一定要加 where 条件,否则整张表
    都删了

    实践 1 例如:删除表 test 中编号为 1 的记录
    mysql> select * from test;
    +----+------+-----------+-------------+
    | id | age | name | shouji |
    +----+------+-----------+-------------+
    | 1 | NULL | oldgirl | NULL |
    | 2 | NULL | 老男孩 | NULL |
    | 3 | NULL | etiantian | NULL |
    | 4 | 24 | pengchun | 13511111111 |
    +----+------+-----------+-------------+
    4 rows in set (0.00 sec)
    mysql> delete from test where id=1;
    Query OK, 1 row affected (0.00 sec)
    mysql> select * from test;
    +----+------+-----------+-------------+
    | id | age | name | shouji |
    +----+------+-----------+-------------+
    | 2 | NULL | 老男孩 | NULL |
    | 3 | NULL | etiantian | NULL |
    | 4 | 24 | pengchun | 13511111111 |
    +----+------+-----------+-------------+
    3 rows in set (0.00 sec)
    实践 2 删除表中 name=pengchun 的行
    mysql> select * from test;
    +----+------+-----------+-------------+
    | id | age | name | shouji |
    +----+------+-----------+-------------+
    | 2 | NULL | 老男孩 | NULL |
    | 3 | NULL | etiantian | NULL |
    | 4 | 24 | pengchun | 13511111111 |
    +----+------+-----------+-------------+
    3 rows in set (0.00 sec)
    mysql> delete from test where name='pengchun';
    Query OK, 1 row affected (0.00 sec)
    mysql> select * from test;
    +----+------+-----------+--------+
    | id | age | name | shouji |
    +----+------+-----------+--------+
    | 2 | NULL | 老男孩 | NULL |
    | 3 | NULL | etiantian | NULL |
    +----+------+-----------+--------+
    2 rows in set (0.00 sec)​

    20.2 通过 update 伪删除数据

    在开发人员开发程序时,页面显示,一般是通过状态来判断的,举例:test 表如下数据

    mysql> select * from test;
    +----+------+-----------+--------+
    | id | age | name | state
    +----+------+-----------+--------+
    | 2 | NULL | 老男孩 1 |
    | 3 | NULL | etiantian | 1 |
    +----+------+-----------+--------+
    2 rows in set (0.00 sec)
    页面正常显示的数据:select * from test where state=1;
    删除上述 oldgirl 的记录:update test set state=0 where name=‘oldgirl’;
  • 相关阅读:
    【Vue前端】Vue前端注册业务实现!!!【代码】
    QQ第三方登录逻辑(微信,微博等同)
    发送短信验证码逻辑
    web图形验证码逻辑
    PID算法资料【视频+PDF介绍】
    如何配置电脑本地的域名
    js实现阻止默认事件preventDefault与returnValue
    js实现事件监听与阻止监听传播
    json字符串转换对象的方法1
    json字符串转换对象的方法
  • 原文地址:https://www.cnblogs.com/hackerlin/p/12539904.html
Copyright © 2011-2022 走看看