zoukankan      html  css  js  c++  java
  • mariadb_2 单表的增删改查

    命令关键字:

    创建表

     create

    删除表

     drop

    修改表的内容

     update

    修改表的结构

     alter

    删除表中内容

    delete

    增加表中内容

    insert

    查询表中内容

    select

    查询语句选项:

    消除重复行

    distinct

    模糊查询

    like

    非连续范围查询

    in

    连续范围查询

    between……and……

    取反

    not

    为空

    is null

    不为空

    is not null

    排序

    order by

    升序

    asc

    降序

    desc

    统计总数

    count

    最大值

    max

    最小值

    min

    求和

    sum

    平均

    avg

    保留小数

    round

    分组

    group by

    显示分组内容

    group_concat

    条件

    having

    分页

    limit

    语句格式:
    字段名称可以写具体的名称,多个字段用逗号隔开,
    也可以写*,*表示所有字段
    一、创建:
    create  table 表名  add 字段名称 数据类型 约束条件,字段名称 数据类型 约束条件,...
    
    二、修改:
    1.修改字段的数据类型和约束条件
    alter table 表名 modify 字段名称 数据类型 约束条件
    
    2.修改字段的名称,数据类型和约束条件
    alter table 表名 change 字段原名称 字段新名称 数据类型 约束条件
    
    3.删除字段
    alter table 表名 drop 字段名称
    
    4.删除表:
    drop table 表名
     
    5.增加表中内容
    insert into 表名 values (值,值,...),值,值,...)
    
    6.增加表中部分内容:
    insert into 表名 (字段名,字段名,字段名...) values (值,值,值...),(值,值,...)
    
    7.修改表的内容:
    update table 表名 set 列1=值1,列2 =值2,....
    
    
    三、删除
    1.物理删除:
    清空表:
    delete  from  表名
    
    删除指定条件的记录:
    delete  from  表名  where  条件
    
    2.逻辑删除: 
    alter table 表名 add 字段名 bit(n)     
    该字段用来做逻辑判断,bit(n)  n表示0和1有 2^n 种组合方式
    delete  from  表名  where  条件 
    该条件是用来指定要删除的逻辑条件
    
    四、查询
    1.查询:
    select 字段名称 from 表名 where 条件
    
    2.给字段起别名:
    select 字段名称 as 别名 from 表名 where 条件
    
    3.给表起别名:
    select 表的别名.字段名称  from 表名 as 表的别名 where 条件
    
    4.消除重复行:
    select distinct 字段名称 from 表名 where 条件
    
    5.条件查询:
    比较运算符:>,<,>=,<=,=
    select 字段名称 from 表名 where 条件
    select 字段名称 from 表名 where 条件1 and 条件2
    select 字段名称 from 表名 where 条件1 && 条件2
    select 字段名称 from 表名 where 条件1 or 条件2
    select 字段名称 from 表名 where 条件1 || 条件2
    
    6.模糊查询:
    select 字段名称 from 表名 where 字段名 like '%_%'(此处可以指定包含%,_,字符等的任意组合)
    
    %:表示匹配0个或者多个字符
    例如:'%周%' 就是匹配包含 周 的所有
    _:表示一个字符
    
    7.in:表示非连续范围内的查询
    select  字段名称 from 表名 where 字段名 in (查询的范围)
    
    8.between …… and :表示连续范围的查询
    select  字段名称 from 表名 where 字段名 between …… and ……
    
    9、not:表示取反
    select 字段名称 from 表名 where 字段名 not 条件
    
    10. 空和非空
    select 字段名称 from 表名 where 字段名 is null
    select 字段名称 from 表名 where 字段名 is not null
    
    11.order by :排序
    asc:升序排列,desc:降序排列 默认是升序
    
    select 字段名称 from 表名 order by 字段名 asc
    select 字段名称 from 表名 order by 字段名 desc
    
    12.聚合函数
    
    count:统计数量
    select count(字段名称) from 表名 where 条件
    
    max:最大值
    select max(字段名称) from 表名 where 条件
    
    min:最小值
    select min(字段名称) from 表名 where 条件
    
    sum:求和
    select sum(字段名称) from 表名 where 条件
    
    avg:平均
    select avg(字段名称) from 表名 where 条件
    
    13.分组
    select 字段名称 from 表名 group by 字段名 (以字段名进行分组)
    select 字段名称,group_concat(字段名) from 表名 group by 字段名(分组并且列出组内内容)
    select 字段名称,group_concat(字段名) from 表名 group by 字段名 having 条件 
    (分组并且列出组内符合条件的内容)
    
    14.分页:
    select 字段名 from 表名  limit  起始位,显示个数
    

      

  • 相关阅读:
    解决Strokeit在win8下的图标问题和开机启动问题
    解决 笔记本键盘打字母却跳出数字来,每次都要按一遍Fn+Num LK 的问题
    Google API在线生成二维码的方法
    解决安装vc2005运行库时提示Command line option syntax error.Type Command/?for Help
    PHP自动发邮件
    java核心技术之java平台的理解
    基于MPI的矩阵相乘summa算法实现(附源程序)
    采用概率算法,估计整数子集1~n的大小
    采用MPI_Send 和MPI_Recv 编写代码来实现包括MPI_Bcast、MPI_Alltoall、MPI_Gather、MPI_Scatter 等MPI 群集通信函数的功能
    PWM控制蜂鸣器实验(附源代码)
  • 原文地址:https://www.cnblogs.com/leeeel/p/10846088.html
Copyright © 2011-2022 走看看