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
    select * from 表名 where 列名 like '%值%'
    select * from 表名 where 列名 between A and B
    select * from 表名 where 列名 in(值)
    select * from 表名 limit n,m
    select * from 表名 order by 列名 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 表)
    相关子查询
    子查询和父查询存在互相的关系,子查询需要用到父查询的内容

  • 相关阅读:
    blk_update_request: I/O error, dev fd0, sector 0
    将MySQL数据迁移到Redis
    专职DBA-MySQL DAL(Data Access Layer)中间件总结
    搞笑聊天(一)
    看图写话(一)
    NFS存储服务
    rsync备份服务
    专职DBA-使用Python操作MySQL数据库
    如何解决SecureCRT无法选择Monaco等其他字体
    MySQL架构类型
  • 原文地址:https://www.cnblogs.com/liuran123/p/5984014.html
Copyright © 2011-2022 走看看