zoukankan      html  css  js  c++  java
  • MySQL中增删改操作

    一.插入数据

    1.1使用insert...values语句插入

    语法:insert   [low_priority|delayed|high_priority](优先级问题,ow_priority是指降低insert和delecte以及update的优先级吗,选择delayed是指将插入消息放入到一个缓冲区中等到表空闲时在插入,high_priority是指insert和select语句优先执行)  into 表名(字段名...)   values (值....)

    实例:

    首先创建一个表如下:

    create table text1(
       tid int not null  primary key auto_increment,
       tnum1 int not null ,
       tday datetime not null
    );

    插入语句:

    insert into text1 values(1,0,"2017-05-19 08:15:00");

    当然你也可以部分插入:

    insert into text1 (tnum1,tday) values(5,"2015-05-19 09:00:00");

    没有插入的项首先要不能有not null约束,如果有那就必须要有默认值,在一个你如果是主键自增长,MySQL会自动为你在上一条记录上加一。

    插入多条记录:

    insert into text1 (tnum1,tday) values (5,"2015-05-19 09:00:00"),
    (5,"2015-08-19 06:20:10"),
    (5,"2013-06-20 01:00:00")
    ;

    1.2使用insert...set语句插入

    语法:insert   [low_priority|delayed|high_priority]  into 表名  set 字段名1 ={值1},字段名2={值2}

    实例:

    insert into text1 set tnum1=110, tday="2015-05-19 09:00:00";

    1.3插入查询结果

    语法:insert  [low_priority|delayed|high_priority] into 表名 (字段名1....) select ....

    实例:

    insert into text2(tnum1,tday) (select tnum1,tday from text1 ) ;

    这样就将text1表中的数据全部copy到了tetx2中,但是我在select语句后面加上where语句时可以运行不报错,但是没有运行效果。

    二.修改表数据

    语法:update [low_priority](MySQL5.5以上默认引擎不支持) [ignore](选择ignore出现错误也要更新) 表名  set

                           字段1=值1,

          字段2=值2,

       where 条件

       [order by ...]  选定修改行的次序

       [limit 行数]  选定修改的行数限制

    例子:

    update text1 set 
         tnum1 = 500
         where tid=1;

    三.删除数据

    删除某行

    语法:delect [low_priority]  [quick] [ignore] from 表名

       where 条件

       [order by ...]  选定修改行的次序

       [limit 行数]  选定修改的行数限制

    例子:

    delete from text1 where tnum1 =500;

     删除全部数据,但是保留表结构:truncate table 表名

    例子:

    truncate table text1;
  • 相关阅读:
    MySQL 数据库主从复制架构
    程序员的双十一
    MySQL 数据库事务与复制
    十字路口的程序员
    瞬息之间与时间之门
    HDFS 与 GFS 的设计差异
    HDFS 异常处理与恢复
    HDFS Client 设计实现解析
    HDFS DataNode 设计实现解析
    HDFS NameNode 设计实现解析
  • 原文地址:https://www.cnblogs.com/SAM-CJM/p/9651249.html
Copyright © 2011-2022 走看看