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;
    
  • 相关阅读:
    学习计划 23月
    bash学习笔记
    bash 中 while读取文件并通过 ssh执行命令出现的问题及解决方法
    bash 学习笔记2
    fedora 启动 openssh
    lesson5 键盘的应用
    第十三章 int指令
    第十五章 外中断
    第十二章 内中断
    第十四章 端口
  • 原文地址:https://www.cnblogs.com/skymyyang/p/7159702.html
Copyright © 2011-2022 走看看