DELPHI事务


--测试环境
create table table1(id int primary key)
insert table1 select 1
union  all    select 2
--查看表
select * from table1
--操作A(执行错误后,事务没有回滚)
begin tran
delete From table1 where id=1
Insert into A(Field1) values(3) --事务没有回滚
commit tran
--操作B(执行错误后,事务回滚)
BEGIN TRY
begin tran//创建还原点
delete From table1 where id=1
Insert into A(Field1) values(3)
commit tran//提交数据
END TRY
BEGIN CATCH
 
ROLLBACK//遇到问题,捕获后回滚到还原点
END CATCH

  con1.BeginTrans;
  try
     with qry1 do
    
begin
       close;
       sql.clear;
       sql.Text:
='delete From table1 where id=1 ;Insert into table1(Field1) values(3)';
       ExecSQL;
    
end;
     con1.CommitTrans;
  except
     con1.RollbackTrans;
 
end;

原文地址:https://www.cnblogs.com/chengxin1982/p/1357139.html