zoukankan      html  css  js  c++  java
  • MySql 小记

    MySql  简单 小记 以备查看
    1.sql概述
    1.什么是sql?
    2.sql发展过程?
    3.sql标准与方言的关系?
    4.常用数据库?
    5.MySql数据库安装?

    2.关键概念
    表结构----------->类的属性
    一行------------->一个对象

    3.建库代码
    1.create database 数据库名
    2.带字符集
    3.带校验规则 collate 验证规则
    create database 数据库名 character set utf8 collate utf8_general_ci;
    4.show create database 数据库名
    5.显示所有数据库
    6.删除一个数据库
    7.使用一个数据库


    4.建表
    *create table 表名(
    列名 类型,
    列名 类型
    );

    2.查看建表的代码
    3.查看所有的表
    4.查看表的详细信息 desc 表名
    5.表中列的常见操作
    1.添加一列
    2.删除一列
    3.修改列的数据类型
    4.修改列名
    6.修改表名
    7.删除表结构

    *5.插入数据
    insert into 表名(列名) values(值,值);
    *6.删除数据
    delete from 表名 where 条件
    truncate table 表名
    *7.修改数据:
    update 表名 set 列名=新值,列名=新值 where 条件
    *8.查看表中数据
    select * from 表名 where 条件 group by 分组 having(分组后条件) order by 排序字段 (asc|desc)


    9。数据完整性
    1.域完整性
    not null
    unique

    2.实体完整性
    主键(自动增长):唯一性,非空性
    primary key

    3.参照完整性
    外键
    constraint 外键名 foreign key (外键字段名) references 主键表(主键名)
    alter table 表名 drop foregin key 外键名;
    表与表之间的关系:
    一对多

    多对多

    一对一
    1.外键+唯一约束
    2.主键+外键

    *10.连接查询
    1.交叉连接
    A cross join B
    from A,B
    2.内连接
    from A inner join B on(A.id=B.bid) where 条件
    3.外连接
    左外连接
    from A left join B on (A.id = B.bid) where 条件
    右外连接
    from A right join B on (A.id = B.bid) where 条件

    4.子查询
    select name=(select name from b ) from A where id in (select id from B where 条件)

    select (子查询) from (子查询) A where id in( 子查询)

    5.联合查询
    union

    select * from A
    union
    select * from B

    6.报表查询
    max()
    min()
    avg()
    sum()
    count()

    7.常用函数
    select now();
    select current_time();
    select current_date();
    select md5('')


    8.备份与恢复
    1.windows命令
    mysqldump -h localhost -u root -p mydb1>mydb1.sql
    2.恢复
    1.windows命令
    mysql -u root -p mydb2<d:/mydb1.sql
    2.mysql命令
    create database mydb3;
    use mydb3;
    source d:/mydb1.sql

  • 相关阅读:
    mysql 触发器
    Yii 1.0 基础
    python解释执行原理(转载)
    python中使用selenium调用Firefox缺少geckodriver解决方法
    Python中os和shutil模块实用方法集锦
    pytesseract使用
    anaconda安装第三方库
    anaconda spyder异常如何重新启动
    windows下python3.6 32bit 安装django
    设置SO_RECVBUF和SO_SENDBUF套接字选项
  • 原文地址:https://www.cnblogs.com/weixiaozhekan/p/5167154.html
Copyright © 2011-2022 走看看