zoukankan      html  css  js  c++  java
  • SQL-结构化查询语言(2)

    使用explain查询select查询语句的执行计划
    mysql> explain select * from student where Sname='金克斯'G
    *************************** 1. row ***************************
               id: 1
      select_type: SIMPLE
            table: student
       partitions: NULL
             type: ref
    possible_keys: index_Sname
              key: index_Sname
          key_len: 50
              ref: const
             rows: 1
         filtered: 100.00
            Extra: NULL
    1 row in set, 1 warning (0.00 sec)
    
    修改表中的数据
    1:命令语法
    update 表名 set 字段=新值 ... where 条件(一定要注意条件)
    update student set Sname='莫甘娜' where Sno=6;
    2:mysql -uroot -p123456 -U 登陆进去的时候执行更新操作必须跟key值可以避免误操作
    alias mysql = 'mysql -U'
    
    删除表中的数据
    delete from test where id=1;
    delete from test,不加条件的话,就是全部删除,是非常危险操作!
    truncate table test;清空表中的数据
    truncate 和 delete 的区别
    1:truncate更快,清空物理文件
    2:delete是逻辑删除,一行一行的删
    
    增删改表的字段
    alter table 表名 add 字段 类型 其他
    alter table test add sex char(4);
    alter table test add age int(2) after name; 在name后面添加age列,插在指定位置
    atler table test add qq varchar(15) first; 将qq列放在第一
    修改字段名称
    alter table test change age oldage char(4) after name;
    修改字段类型
    alter table test modify age char(4) after name;
    
    更改表名
    rename table test to test1;
    alter table test rename to test1;
    
    删除表
    drop table test;
    
  • 相关阅读:
    多测师讲解htm_L标题标签001_高级讲师 肖sir
    Shell特殊变量介绍与实践 $0
    shell 变量定义技巧总结
    shell 环境变量的知识小结
    前端 chrome查看html样式基本操作
    shell 命令 env
    date 命令
    shell 命令 set命令
    shell export 命令
    前端 html span标签
  • 原文地址:https://www.cnblogs.com/skymyyang/p/7159702.html
Copyright © 2011-2022 走看看