Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

"The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION."

$
0
0

Hi,

I checked other threads; they don't seem to answer this question, which is very basic. I've tried the MS Help but it's clear as mud.

I come from an Oracle background. I'm learning SQL Server because, well, it's good to at least have elementary knowledge of another database.

My first step: create a basic one column table, and then try to put some data into it. But when I try to commit, I get an error.

In Oracle, you don't need to explicitly start a transaction. But you do need to commit it (unless you log off with autocommit set, which autocommits on disconnection of a session).

I am wondering how Sql Server handles it.  When I issue "INSERT INTO T VALUES ('X');" and then hit F5 (or press "execute"), it seems the insert statement is autocommited. Is that true?

There seems to be some variable called TRANCOUNT which I think tells you the number of outstanding transactions - is that correct? If I issue

INSERT INTO T VALUES ('X');
PRINT @@TRANCOUNT

then the row is inserted and TRANCOUNT is apparently zero. Does that mean that the INSERT has been autocommitted?

If I then issue COMMIT, I get the error:

"The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION."

What's going on here?  Is BEGIN TRANSACTION optional? I'd appreciate some basic info on the default handling of transactions in SQL Server, thanks.

Jon



Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>