mysql事务是用于处理操作量大、复杂性高的数据
原子性:确保每个事务都有已完成或未完成的操作,不能卡在中间;如果事务在执行过程中出现错误,将回滚到事务开始之前的状态。
[En]
Atomicity: ensure that each transaction has operations that are either completed or not completed, and cannot be stuck in the middle; if an error occurs during the execution of the transaction, it will be rolled back to the state before the start of the transaction.
一致性:在事务开始和结束后,确保数据库的完整性不被破坏,并按照数据库要求的规范写入数据。
[En]
Consistency: after the beginning and end of the transaction, ensure that the integrity of the database is not broken, and the data is written according to the specifications required by the database.
隔离:数据库允许多个事务同时读写数据,而隔离可以防止多个事务交叉执行导致的数据不一致;事务隔离分为四个级别。[出现:√不会出现:×]
[En]
Isolation: the database allows multiple transactions to read and write data at the same time, while isolation can prevent data inconsistencies caused by cross execution of multiple transactions; isolation in transactions is divided into four levels. [appear: √ will not appear: ×]
持久性:提交事务后对数据库所做的更改是永久性的。
[En]
Persistence: changes made to the database after the transaction is committed are permanent.
脏读:一个事务在处理过程中读取另一个未提交的事务数据,最终导致提交未提交的数据时数据不一致。
[En]
Dirty reading: one transaction reads another uncommitted transaction data during processing, which eventually leads to data inconsistency when the uncommitted data is committed.
不可重复读取:当一个事务从多个查询返回数据时,另一个事务修改数据并提交,从而导致前一个事务数据的结果不同。
[En]
Unrepeatable reading: when one transaction returns data from multiple queries, another transaction modifies the data and commits it, resulting in different results of the previous transaction data.
幻读:A事务将数据修改完毕时,同一时间B事务新增一条数据,A事务提交后查询发现还有一条数据没有进行修改,好似产生幻觉一样则为幻读。
该索引可以加快数据库的查询速度,高效地获取指定的数据。
[En]
The index can speed up the query speed of the database and obtain the specified data efficiently.
*
– 优势
+ 提高数据检索效率,降低数据库IO成本
+ 通过索引列可以对数据进行排序,降低CPU消耗
+ 确保数据唯一性
+ 加速表与表之间连接,实现表与表之间参照完整性
– 劣势
+ 占据磁盘空间
+ 降低更新表的效率
创建索引
普通索引:
create index 索引名称 on 表名(列名)
其他索引(举例唯一索引unique):
公式:
create unique index 索引名称 on 表名(列名)
实例:
create table Demo(id int,
name varchar(20),
sex int,
unique index Demo_id(id ASC));
删除索引
删除:
公式:
drop index 索引名 on 表名;
实例:
drop index Dmoe_id on Demo;
*
– 主键索引(primary key):对主键进行索引,主键不允许空值。
– 普通索引(index/key):默认类型,无限制,允许定义索引时有重复值和空值。
– 唯一索引(unique key):专注于对唯一类型数据进行索引,允许空值。
– 全文索引(full key):用于数值比较、范围过滤、关键字匹配的范围性快速查询。
– 联合索引:多列值组成索引,用于多列组合查询。
*
– 索引不是越多越好,数据量小的表不建议添加索引
– 不建议在经常增删改操作的表中添加索引
– 索引一般添加在需要索引的列上
SQL是一种结构化查询语言,用于对数据进行插入、查询、更新、删除操作来管理数据库系统。
*
– 简单易学,操作性强
– 大多数数据库都支持SQL
– SQL操作数据库时大部分的工作由DBMS来完成
*
– DDL[数据定义语言]:用于操作数据库、表、列,常用语句create、alter、drop;
– DML[数据操作语言]:用于操作数据库中数据,常用语句insert、update、delect;
– DCL[数据控制语言]:用于操作访问权限和安全级别,常用语句grant、deny;
– DQL [数据查询语言]:用于查询数据,常用语句select;
*
– insert into:数据插入操作,语法为insert into 表名(列1,列2 )value(值1,值2),插入时列名和值需要一一对应。
– select from:数据查询操作,语法为select * from 表名;则代表全部列名,可通过输入列名来查询特定数据。
– update set:更新操作,语法为update 表名 set 条件A where 条件B,条件A为修改条件,条件B为修改操作。
– delete from:删除操作,语法为delect from 表名 where 条件A,条件A为删除条件。
– where:用于sql中条件判断、条件过滤等操作。
– having:类似于where,一般使用于group by之后,与where区别在于where过滤行,having过滤组。
– like:用于模糊查询,主要只针对于”字符型”字段,常用”_”和”%”这两种通配符,前者充当占位符,后者代表匹配任意字符。
– order by:用于数据排序,常用ASC升序排列和DESC降序排列。
– group by:用于对字段进行分组。
– not:用于判断表达式真假,类似于java语言中boolean。
– and:用于在where子句后面将多个条件结合起来。
– between:用于取两个值之间的数据范围。
– lnner join:内连接,多表连接时只会显示满足条件的数据结果。
– left join:左连接,多表连接时只会以左表为基准显示左表全部数据,右表只会显示对应数据,若无对应数据显示null。
– right join:右连接,与左连接相反;多表连接时只会以右表为基准显示左表全部数据,左表只会显示对应数据,若无对应数据显示null。
– in:*用于嵌套语句查询,常用语子查询中。
*
– 每个字段具有原子性不可再分。
– 建立在第一范式的基础上,确保数据库表列中只保存一种数据,不可以把多种数据保存在一个数据库表列中。
– 建立在地二范式的基础上,数据不能存在传递关系,数据库中每个字段和主键都是直接关系。
*
– 系统需求分析
– 概念结构设计
– 逻辑结构设计
– 物理结构设计
– 数据库实施
– 数据库运维
Original: https://www.cnblogs.com/Lokemow/p/LokemowKai_mysql.html
Author: Lokemow
Title: Mysql自序整理集
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/507832/
转载文章受原作者版权保护。转载请注明原作者出处!