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’;
  • 相关阅读:
    [Error]错误 C2660: Gdiplus::GdiplusBase::operator new: 函数不带三个参数
    opengl多线程的问题
    去掉CFormView的滚动条
    DevIL库使用时图片翻转的问题
    让notepad++正确显示actionscript文件语法高亮
    [Error]world geometry is not supported by the generic scenemanager
    3d Max 9的"正在验证许可证"问题的解决
    CSizingControlBar Error C2440: “static_cast”: 无法从“UINT (__thiscall CSizingControlBarG::* )(CPoint)”转换为>>>
    MFC下的OpenGL
    酷!不用外挂,Win7资源监视器查看QQ好友IP
  • 原文地址:https://www.cnblogs.com/hackerlin/p/12539904.html
Copyright © 2011-2022 走看看