0
点赞
收藏
分享

微信扫一扫

MySQL事务处理介绍


MySQL事务处理(增删改查后只要没有commit,全可以回滚)
		    *myisam引擎不支持事务,innodb(支持外键和事务)才支持事务
			修改表引擎方法:alter table t1 engine=innodb
			
			一:事务操作
				查看是否自动提交:select @@autocommit;	
				关闭自动提交
				set autocommit=0;
				delete from t1 where id>5;  数据只是临时删除,如果commit就真正的执行删除语句
				rollback;     只要没commit还原刚才删除的数据
				commit;
			
			二:还原点的使用:
				insert into t1 values("user4");
				savepoint p1;
				insert into t1 values("user5");
				savepoint p2;
				insert into t1 values("user6");
				savepoint p3;
				
				--3个数据已经插进去啦,能后你觉得user6不要,你就找到还原点 savepoint p2就行
				rollback to p2;    --还原到P2  user6不要
				commit;



举报

相关推荐

0 条评论