1.一个简单事务
1.一个简单事务
CREATE PROCEDURE Pro_Insert(
@id varchar(5),
@name varchar(20))
as
declare @ExistFlag int
set @ExistFlag=(select count(*) from t where id=@id)
begin transaction DoInsert
insert into t(id,name) values(@id,@name)
if @ExistFlag > 0 rollback transaction DoInsert
else commit transaction DoInsert
go
本文介绍了一个简单的SQL存储过程,该过程使用事务来确保数据的一致性和完整性。具体包括创建存储过程、开始事务、插入数据及回滚或提交事务等步骤。

被折叠的 条评论
为什么被折叠?



