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

数据库的最核心也是最常用的 *** 作是什么,第1张

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

如果你想了解更多关于数据库的知识,可以点击: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 是在聚合的基础上再筛选

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

以上就是数据库的最核心也是最常用的 *** 作是什么的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/732165.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存