前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySQL学习小结

MySQL学习小结

作者头像
黑泽君
发布2018-10-11 11:14:08
4860
发布2018-10-11 11:14:08
举报
文章被收录于专栏:黑泽君的专栏黑泽君的专栏

MySQL学习小结

代码语言:javascript
复制
一、数据库:存储、维护和管理数据的集合。
    DB、DBMS
    
二、SQL:结构化查询语言
    SQL的分类
        (1) DDL:数据定义语言,定义数据库对象,对对象进行操作的。
            create    alter    drop
        (2) DML:数据管理语言,对数据库表中的数据进行操作的。
            insert    update   delete
        (3) DQL:数据查询语言,对数据进行查询的。
            select
        (4) DCL:数据控制语言,对数据进行权限访问和安全级别的控制。
            grant(授权)    revoke(收回)
        
    示例:
    DDL:
        create database mydb1;
        use mydb1;
        
        create table student (
            sid int primary key auto_increment,
            sname varchar(50) not null unique,
            sex varchar(10) default '男'
        );
        
        alter table student add birthday date;
        alter table student drop birthday;
        alter table student add grade double(3, 1);
        alter table student modify sex varchar(20);
        alter table student change sname stuname varchar(50);
        
    DML:
        insert into student (sname, sex, grade) values ('tom', default, 98);
        insert into student (sname, sex, grade) values ('lucy', '女', 95);
        insert into student (sname, sex, grade) values ('bruce', '女', 59);
        
        update student set sex = default, grade = 99 where sid = 3; -- 或者
        update student set sex = default, grade = 99 where sname = 'bruce';
        
        
        delete from student where sid = 1;
        delete from student;
        truncate table student;
    
    DQL:
        -- 查询分数与tom分数一样的学生信息
        select * from student where grade = (
        select grade from student where sname = 'tom');
        
        select xxx from xxx where xxx group by xxx having xxx order by xxx limit; -- 书写顺序
        from xxx where xxx group by xxx having xxx select xxx order by xxx limit; -- 执行顺序
        
        where xxx like / between and / in / not in / is null / is not null / and / or / not /
        
        sum() avg() max() min() count() 
        
        ifnull(comm, 0)

三、数据完整性
        实体完整性:行级约束。
        primary key    
        unique    
        auto_increment
        域完整性:列级约束。
        数据类型    
        not null    
        default       
        check()
        引用完整性:参照/关联完整性。
        foreign key    
        
        表与表之间的关系:
            一对多/多对一
            多对多
            一对一
            
四、多表查询
    合并查询:union    union all
    连接查询:
        内连接查询:[inner] join xxx on xxx
        外连接查询:[outer] join xxx on xxx
                        left join xxx on xxx
                        right join xxx on xxx
        自然连接查询:natural join
                        natural left join
                        natural right join
    子查询:
    自连接查询:
    
五、MySQL中的函数
    时间、日期相关函数
    字符串相关函数
    数学相关函数
    
六、MySQL数据库的备份与恢复
    生成SQL脚本 导出数据
    执行SQL脚本 恢复数据
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-04-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档