zoukankan      html  css  js  c++  java
  • 数据库学习内容复习

    1.创建数据库
    create database 数据库名称
    删除数据库
    drop database 数据库名称

    2.创建表
    create table 表名
    (
    列名 类型(长度) 自增长 主键 非空,
    )
    自增长:auto_increment
    主键:primary key
    非空:not null
    外键:foreign key 列名 references 表名(列名)

    删除表
    drop table 表名

    3.CRUD操作

    insert into 表名 values(值)                                           创建
    insert into 表名(列名) values(值)

    delete from 表名 where 条件                                             删除

    update 表名 set 列名=值 where 条件                         修改列名

    select * from 表名
    select 列名 from 表名                                            查询列名
    select * from 表名 where 条件                  根据条件查
    select * from 表名 where 条件1 or 条件2            根据多条件查询   或用or  并列用  and
    select * from 表名 where 列名 like '%值%'                      模糊字查询
    select * from 表名 where 列名 between A and B                           范围查询
    select * from 表名 where 列名 in(值)                    离散查询  不在里面用not  in
    select * from 表名 limit n,m                        分页查询  跳过m条取n条
    select * from 表名 order by 列名 desc                                                 排序查询  降序 desc  默认升序
    select * from 表名 group by 列名 having 条件                                        分组查询

    聚合函数
    select count(*) from 表名                                                       数量  数据的条数
    select sum(列名) from 表名                                                       数据的和
    select avg(列名) from 表名                                                      数据平均值
    select max(列名) from 表名                                                       数据最大值
    select min(列名) from 表名                                                            数据最小值
    select distinct 列名 from 表名                                                     去重复

    高级查询:
    1.连接查询
    select * from 表1,表2 where 连接条件

    另一种写法
    select * from 表1 join 表2 on 连接条件

    2.联合查询
    select 列名 from 表1
    union
    select 列名 from 表2

    3.子查询
    无关子查询
    子查询和父查询没有关系,子查询可以单独执行
    select * from 表 where 列=(select 列 from 表)
    相关子查询
    子查询和父查询存在互相的关系,子查询需要用到父查询的内容

  • 相关阅读:
    android学习十四(android的接收短信)
    C/C++知识要点4——printf函数以及cout的计算顺序
    HDU 5355 Cake(2015多校第六场,搜索 + 剪枝)
    微信错误提示code= -4/微信发送被拒绝
    struts2的validate在使用过程中的一个问题
    28.字符串的排列
    Redis入门经典——The Little Redis Book (翻译)
    POJ 3155 Hard Life(最大密度子图)
    BZOJ 1798 AHOI2009 Seq 维护序列 线段树
    RT-Thread开篇
  • 原文地址:https://www.cnblogs.com/sq45711478/p/5983662.html
Copyright © 2011-2022 走看看