MySQL语句操作数据库总结

  最近在温习数据库的相关知识,为了避免遗忘,所以发出来和大家分享,不对的地方还请多多指正!奋斗

 1. 创建/删除数据库

        create database 数据库名

        drop datebase 数据库名

  2. 创建/删除表

      create table 表名(

      列名1  数据类型   约束,

      列名2  数据类型   约束,

      列名3  数据类型   约束

       )

       drop table 表名

       truncate table 表名

  3. 插入

        insert into 表名(列名1,列名2,列名3,列名4)

        values(值1,值2,值3,值4),

        (值1,值2,值3,值4),

        (值1,值2,值3,值4)

  4. 修改

      添加/删除列

        alter table 表名 add 列名 数据类型 约束

        alter table 表名 drop [column] 列名

      修改数据类型

        alter table 表名modify column 列名 数据类型

      修改表名/列名

        alter table 表名rename to 新表名

        alter table 表名change 列名 新列名 列类型

      给列添加/删除约束

        alter table 表名add constraint 约束名称 约束类型

        alter table 表名drop constraint 约束名称

  5. 更新

     update表名 set列名=新值 where 列名=某值

  6. 删除

    deletefrom 表名 where条件

  7. 查询

     select *|列名1,列名2,列名3... from 表名1,表名2 

     where 条件表达式

     group by 分组语句

     having 统计函数的比较语句

     order by 排序语句

     其中,条件表达式里的运算符有:=、<、>、>=、<=、and、or、not

     排序查询:desc(降序) asc(升序)

     模糊查询:like(“%”:表示0-n个;“_”:表示1个)

     分组排序:group by,会用到统计函数(sum、count、max、min、avg)


 


猜你喜欢

转载自blog.csdn.net/qq_41541619/article/details/79539461