• 删除mysql数据库表里的记录


    如果记录不再需要,可以用delete 命令进行删除,语法如下:

    DELETE FROM tablename [WHERE CONDITION]

    例如,在emp 中将ename 为‘dony’的记录全部删除,命令如下:

    mysql> delete from emp where ename='dony';
    Query OK, 1 row affected (0.00 sec)

    在MySQL 中可以一次删除多个表的数据,语法如下:

    DELETE t1,t2…tn FROM t1,t2…tn [WHERE CONDITION]

    如果from 后面的表名用别名,则delete 后面的也要用相应的别名,否则会提示语法错误。
    在下例中,将表emp 和dept 中deptno 为3 的记录同时都删除:

    mysql> select * from emp;
    +--------+------------+---------+--------+
    | ename | hiredate | sal | deptno |
    +--------+------------+---------+--------+
    | zzx | 2000-01-01 | 100.00 | 1 |
    | lisa | 2003-02-01 | 200.00 | 2 |
    | bjguan | 2004-04-02 | 100.00 | 1 |
    | bzshen | 2005-04-01 | 300.00 | 3 |
    | dony | 2005-02-05 | 2000.00 | 4 |
    +--------+------------+---------+--------+
    5 rows in set (0.00 sec)
    mysql> select * from dept;
    +--------+----------+
    | deptno | deptname |
    +--------+----------+
    | 1 | tech |
    | 2 | sale |
    | 3 | hr |
    | 5 | fin |
    +--------+----------+
    4 rows in set (0.00 sec)
    mysql> delete a,b from emp a,dept b where a.deptno=b.deptno and a.deptno=3;
    Query OK, 2 rows affected (0.04 sec)
    mysql>
    mysql>
    mysql> select * from emp;
    +--------+------------+---------+--------+
    | ename | hiredate | sal | deptno |
    +--------+------------+---------+--------+
    | zzx | 2000-01-01 | 100.00 | 1 |
    | lisa | 2003-02-01 | 200.00 | 2 |
    | bjguan | 2004-04-02 | 100.00 | 1 |
    | dony | 2005-02-05 | 2000.00 | 4 |
    +--------+------------+---------+--------+
    4 rows in set (0.00 sec)
    mysql> select * from dept;
    +--------+----------+
    | deptno | deptname |
    +--------+----------+
    | 1 | tech |
    | 2 | sale |
    | 5 | fin |
    +--------+----------+
    3 rows in set (0.00 sec)
  • 相关阅读:
    js rsa sign使用笔记(加密,解密,签名,验签)
    金额的计算
    常用js方法集合
    sourceTree 的使用
    node-- express()模块
    详细讲解vue.js里的父子组件通信(props和$emit)
    Vue -- vue-cli webpack打包开启Gzip 报错
    es6函数的rest参数和拓展运算符(...)的解析
    js中判断对象数据类型的方法
    vue学习之vue基本功能初探
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/6197442.html
Copyright © 2020-2023  润新知