zoukankan      html  css  js  c++  java
  • MySQL笔记 -- DML

    MySQL笔记 -- DML

    show databases;
    
    
    create database db_26;
    
    use db_26;
    
    create table tab_2
    (
        tid       int,
        tname     varchar(4),
        # 可变字符,最多4个字符
        tsex      char(1),
        # 固定长度
        tisDy     boolean,
        tscore    float(4, 1),
        # 浮点类型 小数点后1为 整数三位
        tshow     text,
        tbirthday datetime
        # 生日
    );
    
    /**
      DML 数据操作:对表记录的增删该
      关键字 insert delete update
      查询所有 select * from 表名
     */
    
    /**
      添加记录
      insert into 表名(参数列表) values(值1,值2,....)
     */
    insert into tab_2
    values (1001, '韩妹妹', '女', true, 23, '我是一只小小小鸟', '2010-12-13 13:14:15');
    # 不选择参数,默认表顺序
    
    insert into tab_2 (tid, tname, tsex, tisDy, tscore, tshow, tbirthday)
    values (1002, '韩妹妹', '女', true, 23, '我是一只小小小鸟', '2010-12-13 13:14:15');
    # 指定参数
    
    insert into tab_2 (tid, tname, tsex, tisDy, tscore, tshow, tbirthday)
    values (1002, '韩妹妹', '女', true, 23, '我是一只小小小鸟', '2010-12-13 13:14:15'),
           (1002, '韩妹妹', '女', true, 23, '我是一只小小小鸟', '2010-12-13 13:14:15');
    # 插入多行
    
    select *
    from tab_2;
    # 查看表
    
    /**
      修改表
      update 表名 set 列名1=值,列名2=值,....;   修改所有记录
      update 表名 set 列名1=值,列名2=值,.... where 条件    修改指定记录
     */
    update tab_2
    set tsex   = '妖',
        tscore = tscore + 1;
    # 修改所有记录
    update tab_2
    set tsex  = '男',
        tscore=1
    where tid < 2000;
    # 修改指定条件的记录
    
    /**
      删除记录
      delete form 表名 where 条件;          删除指定条件
      delete form 表名;       删除表中所有的记录
      truncate 表名;      删除表中所有的纪录
     */
    /**
      delete 和 truncate 的区别
      相同:都是可以用于删除表记录
      不同 1 delete 是逐行删除 效率比较低           truncate 是删除表中的数据文件 效率高
          2 delete 是 DML,需要事务,可以回滚      truncate 是DDL 没有事务,不能回滚
          3 delete 可以加 where 条件,删除指定行    truncate 不能加 where 条件,只能删除所有行
     */
    delete
    from tab_2
    where tid = 1234;
    truncate tab_2;
    # 删除表中的所有数据
    
    
    
    
  • 相关阅读:
    CodeForces 659F Polycarp and Hay
    CodeForces 713C Sonya and Problem Wihtout a Legend
    CodeForces 712D Memory and Scores
    CodeForces 689E Mike and Geometry Problem
    CodeForces 675D Tree Construction
    CodeForces 671A Recycling Bottles
    CodeForces 667C Reberland Linguistics
    CodeForces 672D Robin Hood
    CodeForces 675E Trains and Statistic
    CodeForces 676D Theseus and labyrinth
  • 原文地址:https://www.cnblogs.com/javayanglei/p/13305280.html
Copyright © 2011-2022 走看看