python学习之老男孩python全栈第九期_数据库day003知识点总结 —— MySQL数据库day3

复习:
    1. 增
        insert into xx(name) values('root'),('xxx');
        insert into xx(name) select id from tb1;
    
    2. 自增
        起始值
        步长:
            - session
            - global
    3. unique 唯一索引
            id name(unique) email(unique)
                1                1
                2                3
            
            id name email unique(name,email)
                1     1
                1     2
    
    4. 排序
        order by id asc        从小到大排序
        order by id desc    从大到小排序
    
    5. 通配符
        select xx from tb1 where name like '%a'
        
    6. limit
    
    7. 连表
        两个表 a,b
        select * from a left join b on a.id=b.id;
    
    8. 删
        delete from tb1;
        truncate table tb1;
        drop table tb1;
        
    9. 分组
        select count(id) from tb1 group by name;
        select count(id) from tb1 group by name having count(id)>2;
        
    10. 筛选条件
        in        not in        between and        !=        and        or
    
    11. 外键:一对一,一对多,多对多
        
        
一. navicat
    - 创建表(外键)
    - 新建查询
    - 转储sql文件
        ...
    在命令行中转储文件:
        备份:(数据表结构+数据)mysqldump -u root db1 > db1.sql -p        
        备份:(数据表结构)mysqldump -u root -d db1 > db1.sql -p            (只有表,没有数据(insert ...))
        
        执行文件,先创建数据库:
        导入文件:
            create database db2;
            mysqldump -u root -p 密码 -d db2 < db1.sql
        
        
二. 临时表
    
    (select * from score where num>60) B;
    select sid from (select * from score where num>60) as B;
        
三. 练习
            

猜你喜欢

转载自www.cnblogs.com/YD2018/p/9451818.html