在哔哩哔哩学mysql的笔记

  • P4
    • 主键
      • 业务主键:找个针对的不会重复的列当主键,身份证号啊工号之类的
      • 逻辑主键:就是单纯的一串数字
    • 表间关联,外键
      • 外键就是一个表中用来指向另一个相关联的表的列
  • P6
    • 常用数据类型:
      • 文本
        • char
        • varchar
        • text
        • tinytext
        • meduimtext
        • longtext
      • 整数
        • tinyint
        • smallint
        • mediumint
        • int
        • bigint
      • 小数
        • decimal
        • float
        • double
      • 日期时间
        • DATE
        • TIME
        • DATETIME
      • 二进制大数据:(图片照片之类的,但实际上项目中是把图片之类的放在文件服务器下)
        • TINYBLOB
        • BLOB
        • MEDIUMBLOB
        • LONGBLOB
  • P7 P8 P9
    • sql语句
      • select
      • insert
        • 设置自动递增
        • 修改数据类型
      • update
      • 用where来做限定,可以使用or  and  not    <    >   <=   >=   !=
      • delete:delete from table(删除整个表中的数据,剩下个空表)
      • drop:删除表,表都没了
  • P10
    • 花式select
      • select name,age from table
      • select name,age+1 from table
      • select 1+1   ----->2
      • select now()  ---------->现在的时间
  • P11 P12 P13 P14 P15 P16 P17
    • 数据汇总
      • 聚合函数
        • MAX : select max(salary) from table
        • MIN : 同上
        • count : select count(*) from table 查出有多少行,即多少条数据
        • sum
        • avg:平均
      • 空值处理
        • NULL代表不知道
        • NULL+1还是NULL
        • select * from table where name != NULL输出为没有
        • select * from table where name is not NULL 表示提取出不为空的结果
      • LIMIT
        • 用来限制返回的结果集,放在select的最后
        • select * from table limit 2,3  从第2条开始的一共3条数据
      • 排序:
        • order by:
          • 要放在sql语句的末尾
          • select * from table order by age desc,salary desc:按照年龄的降序排序,若年龄一样再按照工资降序排列
      • 分组查询:
        • group by:
          • select  age from table group by age  年龄相同的分为一组
          • 计算每个分组中的平均工资select AVG(salary) from table group by age
      • 通配符过滤
        • LIKE
          • _:匹配单个出现的字符,如T__可以匹配TOM
          • %:任意多个字符
          • LIKE的性能较差,会造成全表扫描
  • P18
    • 多个表的联合查询join
      • left join  
  • P19
    • 外键约束:
      • 外键约束建好了之后就不能随便删除一个表的某个记录了,免得弄乱了

猜你喜欢

转载自blog.csdn.net/weixin_38104825/article/details/81637630