English 中文(简体)
Unable to ROLBACK the trade in Sql服务器 2008R2?
原标题:Unable to ROLLBACK the transaction in Sql Server 2008R2?

我的测试表有两栏:

id         int not null  
somecolumn varchar(10))

Now see my query:

USE TRY
BEGIN TRANSACTION T1
INSERT INTO Test VALUES(7, hi );
GO
INSERT INTO Test VALUES(8, hi , ABC );
GO
PRINT @@ERROR
if @@ERROR>0
    ROLLBACK TRANSACTION T1
ELSE
    COMMIT TRANSACTION T1

我知道,我的第二个问题是错的,因为我想进行交易以收回,但插入第一点点,然后表明这一信息:

(1 row(s) affected)  
Msg 213, Level 16, State 1, Line 1
Column name or number of supplied values does not match table definition.
213
问题回答

正如Benedikt已经指出的那样,我们不能在BEGIN和END之间使用GO。 如果你从上述交易中删除该表,那么,由于错误插入书面说明,这些报表甚至无法汇编。 TRY.CATCH赢得了一定的工作(如果你在执行阶段试图追赶错误和回转交易)。





相关问题
WCF Transaction Flow Question

I would like to configure WCF service operations to accept a transaction if my client sends one, but not to create one if none is sent. I think this would be similar to the Supported transaction ...

question about pl/sql exception

the following text is an excerpt of oracle documentation Oracle® Database PL/SQL Language Reference 11g Release 1 (11.1) : Unhandled exceptions can also affect subprograms. If you exit a ...

SQL Server - transactions roll back on error?

We have client app that is running some SQL on a SQL Server 2005 such as the following: BEGIN TRAN; INSERT INTO myTable (myColumns ...) VALUES (myValues ...); INSERT INTO myTable (myColumns ...) ...

Cannot rollback transaction with Entity Framework

I have to do queries on uncommitted changes and I tried to use transactions, but I found that it do not work if there are exceptions. I made a simple example to reproduce the problem. I have a ...

mySQL - Prevent double booking

I am trying to work out the best way to stop double booking in my application. I have a table of unique id s each can be sold only once. My current idea is to use a transaction to check if the ...

热门标签