首页 >数据库 >SQL > 正文

数据库的最核心也是最常用的操作是什么

原创2019-07-30 14:57:3407983

如果你想了解更多关于数据库的知识,可以点击:SQL教程

数据库的最核心也是最常用的操作是增删改查。下面我们为大家介绍一下增删盖查的具体操作语法。

数据库

  查询数据库:show databases;

  创建数据库:create database 库名;

  删除数据库:drop database 库名

  创建表:create table 表名(字段名 数据类型【属性】【索引】)

  查看表结构:desc 表名

  查看表:show tables

  插入数据:insert into 表名 value()

  查看创建表信息:show create table 表名

  查看指定库的表:show tables where 目标库名

字段

  增加:alter table 表名 add 字段名 数据类型 【属性】【索引】

    往指定位置后面插入字段:alter table 表名 add 字段名 数据类型 【属性】 【索引】after 指定的字段名

    往第一个位置插入:alter table 表名 add 字段名 数据类型【属性】【索引】first

  删除:alter table 表名 drop 字段名

  修改:alter table 表名 change 旧字段 新字段 数据类型 【属性】【索引】

  条件语句:> < >= <= != and or 等等

数据

  添加:insert into 表名 value()

  删除:delete from 表名 (慎用,删除整个表数据)

     delete from 表名 where 条件语句

  修改:update 表名 set 字段名=值 where 条件语句

  ★查询:精确查询:select * from 表名 where 条件语句

      运算符查询:select * from 表名 where id = 1+1

            select * from 表名 where id < 100

      逻辑查询:select * from 表名 where and条件

           select * from 表名 where or条件

      模糊查询:select * from 表名 where 列名 like'值'  值:%a%(查找中间有a的数据) a%(查找以a开头的数据) %a(查找以a结尾的数据)

      排序与受限查询:select * from 表名 where order by 列名 desc  desc:表示从大到小排序 asc:表示从小到大排序

              select * form 表名 limit x,y  x:表示跳过多少条 y:表示去多少条

      聚合排序:select count(列名) from 表名  

           count:计算表中某个列或多个列中数据的次数

           avg:平均值

           max:最大值

           min:最小值

           sum:总和  一般用于计算价格

      区间查询:select * from 表名 where 字段 between 0 and 10  查找0到10区间的数据

      分组查询:select 展示的列 from 表名 group by 参考列

           select name,count(列) from 表名 group by name

           select name,count(content) from 表名 group by name having count(content) > 5  having 是在聚合的基础上再筛选

   分组查询一般与聚合查询一起使用

以上就是数据库的最核心也是最常用的操作是什么的详细内容,更多请关注php中文网其它相关文章!

php中文网最新课程二维码

声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理

  • 相关标签:数据库
  • 相关文章

    相关视频


    网友评论

    文明上网理性发言,请遵守 新闻评论服务协议

    我要评论
  • 专题推荐

    推荐视频教程
  • SQL趣味课堂SQL趣味课堂
  • 视频教程分类