mysql-tcl(Transaction Control Language) summary

Transaction: A transaction consists of one or more SQL statements in a single unit. In this unit, each MySQL statement is mutually dependent. The entire single unit as an indivisible whole, if a SQL statement in the unit fails or generates an error, the entire unit will be rolled back. All affected data will return to the state before the transaction started; if all sQL statements in the unit are executed successfully, the transaction will be executed smoothly.

Storage engine: The data in mysql is stored in files (or memory) using various technologies

show engines//查看存储引擎

The results are as follows
Insert picture description here
. The properties of the
Insert picture description here
transaction : the creation of the transaction


	隐式事务:事务没有明显的开启和结束的标记,如insert,update,delete语句
	
	显示事务:必须先设置自动提交功能为off
	set autocommit=0//将自动提交设置为off
	start transaction//可不写
	
	begin//可直接用begin
	语句
	...
	commit//提交事务
	rollback//回滚事务


Isolation level
Insert picture description here

select @@tx_isolation//查询隔离级别
set session transaction isolation level 隔离级别//设置隔离级别


savepoint:

begin
事务
savepoint a;
事务
rollback a;

view:

create view 视图名
as
select 
......
;




select * from 视图名

View modification:

语法1create or replace view 视图名
as
查询语句
...

语法2alter view 视图名
as
查询语句

Delete view:

drop view 视图名,视图名,视图名....

View the view:

desc 视图名
show create view 视图名//创建的过程

Update of the view:

 1.插入:
   insert into 视图名 values ()
 2.修改:
 	update 视图名 set 
 3.修改:
 	delete from 视图名 ....
 

Insert picture description here


variable:

 分类:
 	系统变量:
 			全局变量
 			会话变量
 			
 	自定义变量:
 			用户变量
 			局部变量		
	
一.系统变量
   变量由系统提供,不是用户定义,属于服务器层面
   1.查看所有的系统变量
   show global variables//全局
   show session variables//会话
   show variables//会话
   2.查看满足某种条件的系统变量
   show global|session variables like.... 
   3.查看指定系统变量
   select @@变量名//会话
   select @@global.变量名//全局
   4.为某个系统变量赋值
   set 变量名 =set global.变量名=set @@global|session.变量名=值
二.自定义变量
   
   用户变量(声明时必须赋值)
	   作用域:当前会话
	   1.声明并初始化
	   set @变量名=set @变量名:=select @变量名:=2.更新
	   重新声明
	   select 元素 into 变量名 from//将查询结果赋值给变量
   
   局部变量(仅仅定义在begin end)
   	   1.声明
   	   declare 变量名 类型
   	   declare 变量名 类型 default2.赋值
   	   set 变量名=set 变量名:=select @变量名:=select 元素 into 变量名 from3.查看
   	   select 变量名

   

Stored procedures and functions (similar to java methods, c functions)

1. Stored procedure

.创建
  create procedure 存储过程名(参赛列表)
  begin
  .....
  end
  
  注意:
  1.参数列表包含三部分(不谢参数模式默认in)
  参数模式 参数名 参数类型
  2.参数模式:
  IN 该参数需要调用方传入值
  OUT 该参数可以作为返回值
  INOUT 具备以上23.如果存储过程只有一句话,beginend可以省略
  4.存储过程中每条语句都必须加;
  5.储存过程的结尾可以使用delimiter重新设置
  		语法:
  		delimiter 结束标记

二.调用
   call 存储过程名(实参列表);.删除
   drop procedure 存储过程名;.查看存储过程的信息
   show create procedure 存储过程名
  

2. Function:
difference:
stored procedure: the number of return values ​​is not limited, suitable for batch insertion, update
function: there is only one return suitable for data processing

.创建
	create function 函数名(参数列表) returns 返回类型
	begin
	...
	end
	
	注意:
	 1.参数列表包含:参数名 参数类型
	 2.必须有return语句

二.调用 
 	select	函数名(参数列表).查看函数
	show create function 函数名;.删除函数
	drop function 函数名;

Smooth control structure:

1.if
if(表达式1,表达式2,表达式3)
	表达式1成立,返回表达式2的值,否则返回表达式3的值

2.case
	1.充当java中的switch语句
	case 变量|表达式|字段
	when ..then...
	when ..then...
	else ...
	end
	
	2.充当java中的if else语句
	case 
	when 条件 then...
	when 条件 then...
	else...
	end


3.if结构
	if 条件1 then 语句1
	elseif 条件2 then 语句2
	else
	
	注意:只能放在begin end4.循环
	while:
		while 循环条件 do
			循环体
		end while 
	

	loop:
		loop 
		循环体
		end loop 

	repeat:
		repeat
		循环体
		until 结束循环的条件
		end repeat
		 

5.循环控制:
	iterate :类型于continue
	leave: 类似于break

Related content:
mysql installation tutorial
DQL
DML
DDL


Insert picture description here
                                                                           --A certain scientific super-electromagnetic gun

Guess you like

Origin blog.csdn.net/jahup/article/details/113885060