begin transaction mustt insert into student values(12,'kkk','j大洒扫','j','djhdjh') insert into student values(45,'jhsjhs','j','h','asjkdjk') if @@ERROR<>0 BEGIN ROLLBACK TRANSACTION mustt print 'error' RETURN END COMMIT TRANSACTION mustt //在上面的事务中,当两条插入语句有出现错误的时候,没有错误的就插入到表中,错误的语句不影响到正确的插入语句。
-----------------------------------------------------------------------------------------------------------
保存事物
保存事务: begin transaction savemustt insert into student values(13,'kkk','j','j','djhdjh') save transaction before_insert_data2 insert into student values(46,'jhsjhs','j','h','asjkdjk') ROLLBACK TRANSACTION before_insert_data2 /*这样就以第一条记录为保存点,且只插入第一条记录,*/