zoukankan      html  css  js  c++  java
  • mysql 查询

    select sheng.id as sid,sheng.title as stitle,
    shi.id as shiid,shi.title as shi,
    xian.id as xianid,xian.title as xiantitle
    from areas as sheng
    inner join areas as shi on sheng.id=shi.pid
    inner join areas as xian on shi.id=xian.pid
    where sheng.pid is null and sheng.title='山西省';

    # 视图
    # 对于复杂的查询,在多次使用后,维护是一个非常麻烦的事情
    # 解决:定义视图
    # 视图本质就是对查询的一个封装
    # 定义视图

    # create view v_stu_sub_sco as
    # select students.*,scores.score,subjects.title from scores inner join students on students.id=scores.stuid
    # inner join subjects on subjects.id=scores.subid


    # 事务
    # 当一个业务逻辑需要多个sql完成是,如果其中某条sql语句出错,则希望整个操作都退回
    # 使用事务可以完成退回的功能,保证业务逻辑的正确性
    # 事务四大特性(简称ACID)
    # 原子性(Atomicity): 事务中的全部操作在数据库中是不可分割的,要么全部完成,要么均不执行。
    # 一致性(Consistency):几个并行的事务,其执行结果必须与按某一顺序串行执行的结果一致。
    # 隔离性(Isolation):事务的执行不受其他事务的干扰,事务执行的中间结果对其他事务必须是透明的
    # 持久性(Durability):对于任意已提交事务,系统必须保证该事务对数据库的改变不被丢失,即使数据库出现故障。

    # 要求:表的类型必须是innodb或bdb类型,下可以对此表使用事务

    # 保证一个业务的完整性


    # 查看表的创建语句
    # show create table 表名

    # # 修改表的类型
    # alter table '表名' engine=innodb

    # 事务语句
    # 开启begin
    # 提交commit
    # 回滚rollback


    # 使用事务的情况,当数据更改是,包括insert、update、delete


    # 索引

    # 当数据库中的数据很大时,查找数据会变的很慢
    # 索引能提高数据访问性能
    # 逐渐和唯一索引,都是索引,可以提高查询速度


    # 选择列的数据类型
    # 越小的数据类型通常更好,越小的数据类型通常再磁盘/内存和cpu缓存中国都需要更小的空间,处理起来更快。
    # 简单的数据类型更好,整形数据比起字符,处理开销更小,因为字符串的比较更复杂
    # 尽量避免NULL,应该制定列为NOT NULL,除非你想存NULL,
    # 在mysql中,含有空值的列很难进行查询优化,因为他们是的索引,索引的统计信息以及及比较运算更加复杂。你应该用0/一个特殊的值或者一个空串代替空值

    # 操作
    # 索引分 单列索引和 组合索引
    # 单例索引:即一个索引只包含单个列,一个表可以有多个单利索引,但这不是组合索引
    # 组合索引:即一个索包含多个列

    # 产看索引
    # show index from 表明
    # 创建索引
    # create index indexName on mytable(username(length));


    # 删除索引
    # drop index [index] on mytable


    # 查看时间
    # show profiles

    # 开启运行时间检测
    # set profiling=1;

    # select * from areas where title="山西"

    # show profiles

    # 为表areas的atitle列创建索引
    # create index titleIndex on areas(title(20));

    # select * from areas where title="山西"

    # show profiles

  • 相关阅读:
    Checking Types Against the Real World in TypeScript
    nexus pip proxy config
    go.rice 强大灵活的golang 静态资源嵌入包
    几个golang 静态资源嵌入包
    rpm 子包创建学习
    Rpm Creating Subpackages
    ava 类似jest snapshot 功能试用
    ava js 测试框架基本试用
    The Architectural Principles Behind Vrbo’s GraphQL Implementation
    graphql-compose graphql schema 生成工具集
  • 原文地址:https://www.cnblogs.com/sklhtml/p/9580231.html
Copyright © 2011-2022 走看看