第一周 mysql 1~6章小结

作者: 奋斗的喵儿 | 来源:发表于2020-07-26 19:54 被阅读0次

    一、重点内容

    1、命令行进入sql

    启动sql服务,C:\Users\dell>d:→D:\cd D:\MYSQL\bin→D:\MYSQL\bin>mysql -uroot -p密码

    2、sql语句及创建数据库数据表

    常用3个有括号的语句 version(); now(); database();

    create database python_test1 charset=utf8;

    use python_test1;

    create table student; 

    show tables;

    desc student;

    3、数据表数据类型

    int unsigned 无符号整数

    类型         大小       范围(有符号)      范围(无符号)       用途

    tinyint     1字节          (-128,127)           (0,255)            小整数值

    smallint  2 字节    (-32 768,32 767)     (0,65 535)          大整数值

    mediumint 3 字节 (-8 388 608,8 388 607) (0,16 777 215) 大整数值

    int或integer 4 字节 (-2 147 483 648,2 147 483 647) (0,4 294 967 295) 大整数值

    bigint  8 字节 (-9 233 372 036 854 775 808,9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615) 极大整数值

    decimal(5,2) 5位数其中2位小数

    auto_increment 自动增长

    default 默认值

    primary key 主键

    not null 非空

    enum('','',''); 选项

    varchar(20)  字段长度

    表的增删改查  alter  insert  update  select delete delete

    4、常用的查询

    distinct 列名-消除重复行  

    like 模糊查询  %替换任意个  _替换一个

    in 范围查询 in()   not in()

    is null 空判断

    order by 排序 asc升序  desc降序

    count(1)或count(*)计数   max() min() sum() avg() round() 

    group by 分组查询

    group_concat() 分组的多个结果返回一条

    having  筛选分组后的字句,必须与聚合函数联用; with rollup 汇总;limit 筛选几条数据

    5、连接

    table1 inner join table2 on 关联条件  两表相交部分

    table1 left join table2 on 关联条件  前表+后表与前表相交部分

    6、视图

    创建视图 create view v_student as select 语句

    导入数据 source 路径.sql

    7、时间函数

    日期转换字符串 date_format(日期,字符串格式)

    date_sub(date,interval 1 day);

    date_add(date,interval 1 month);

    timestampdiff(unit,begin,end); 日期指定unit差

    二、遇到的问题及下周计划

    命令行运行代码报错经常由中英文标点符号、单词拼写、遗漏括号等细节导致。

    由于之前sql接触的较少,本周基本保证每天一章的进度完成了sql内容的学习,下周仍需要两天的时间完成练习进行巩固。接下来进入第二阶段。

    相关文章

      网友评论

        本文标题:第一周 mysql 1~6章小结

        本文链接:https://www.haomeiwen.com/subject/ohjwlktx.html