db-tutorial/codes/mysql/tcl_demo.sql

44 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* Mysql TCL 语句示例
* @author Zhang Peng
* @date 2018/5/2
*/
#############################################################
#
#############################################################
-- 新建数据表 user
DROP TABLE IF EXISTS user;
CREATE TABLE user (
id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
username varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户名',
password varchar(64) NOT NULL DEFAULT 'default' COMMENT '密码',
email varchar(64) NOT NULL DEFAULT 'default' COMMENT '邮箱',
PRIMARY KEY (id)
) COMMENT='用户表';
#############################################################
#
#############################################################
-- 开始事务
START TRANSACTION;
-- 插入操作A
INSERT INTO user
VALUES (1, 'root1', 'root1', 'xxxx@163.com');
-- 创建保留点 updateA
SAVEPOINT updateA;
-- 插入操作B
INSERT INTO user
VALUES (2, 'root2', 'root2', 'xxxx@163.com');
-- 回滚到保留点 updateA
ROLLBACK TO updateA;
-- 提交事务只有操作A生效
COMMIT;