|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:48 PM
Points: 7,088,
Visits: 7,143
|
|
Good question.
I managed to get it wrong (thinking the error terminated the batch - as would an "insert value in identity column with identity insert ON" error, for example - so that the answer would be 1); serves me right for answering before breaking my fast, I guess.
There appears to be a bug in the parser which is shown up by this question (not insisting on a comma which thepublished BNF shows as essential). I guess it's a pretty harmless bug, though.
And why oh why does the explanation refer to sql 2000 documentation instead of to documentation for one of the currently supported releases?
Tom Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 10:51 AM
Points: 1,219,
Visits: 13,507
|
|
nice question!!!!
rfr.ferrari DBA - SQL Server 2008 MCITP | MCTS
remember is live or suffer twice!
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:16 PM
Points: 5,101,
Visits: 20,201
|
|
Hugo Kornelis (5/16/2012) Nice question. I knew about implicit transaction, but I had to do some digging because I couldn't remember if primary key violation errors are batch-aborting or not.
(One possible -slight!- improvement to the question would have been to explicitly mention that the three insert statements are executed as a single batch; the current wording can be interpreted as them being executed one by one).
Prior to submitting the question, I tested as a batch, then executing one insert statement at a time. Made no difference to what happens.
have not tested if the code as posted would actually work or complain about the column reference in the column constraint. If it does work, I would classify it as a parser bug, since the description in BOL implies that the seperating column between columns and table constraints is mandatory.
Retested the CREATE TABLE statement not more than 2 minutes ago
CREATE TABLE QODT1(Col1 int NOT NULL,col2 CHAR(1) NOT NULL,col3 VARCHAR(20) CONSTRAINT PK_QODT1 PRIMARY KEY (col1)) It worked when I initially created the question, and it works today.
L' Eomot Inversé In answer as to why I cited as a reference, the statement for SQL 2000, sort of a tongue in cheek action on my part, to show people how long the IMPLICIT TRANSACTIONS feature/rule has been in effect.
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please read Before posting a performance problem please read
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 5:02 AM
Points: 1,149,
Visits: 1,451
|
|
Thanks for the question.
Got it wrong, and I even ran a test. Code below:
CREATE TABLE #Temp(Col1 INT NOT NULL CONSTRAINT PK_QOTD_1 PRIMARY KEY (Col1)) INSERT #Temp(Col1) VALUES (1) INSERT #Temp(Col1) VALUES (1) INSERT #Temp(Col1) VALUES (2) GO
SELECT * FROM #Temp
(not exactly the same code as the question, but functionally equivalent) Only got one row back from SELECT, as I had anticipated.
So, what have I got wrong here?
Please don't go. The drones need you. They look up to you.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:30 PM
Points: 5,235,
Visits: 7,038
|
|
Thomas Abraham (5/16/2012)
Thanks for the question. Got it wrong, and I even ran a test. Code below: CREATE TABLE #Temp(Col1 INT NOT NULL CONSTRAINT PK_QOTD_1 PRIMARY KEY (Col1)) INSERT #Temp(Col1) VALUES (1) INSERT #Temp(Col1) VALUES (1) INSERT #Temp(Col1) VALUES (2) GO
SELECT * FROM #Temp
(not exactly the same code as the question, but functionally equivalent) Only got one row back from SELECT, as I had anticipated. So, what have I got wrong here? No idea what went wrong. I copied and pasted the code above, hit execute, and got two rows back. SQL Server 2012. What version are you running?
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 5:02 AM
Points: 1,149,
Visits: 1,451
|
|
Hugo Kornelis (5/16/2012)No idea what went wrong. I copied and pasted the code above, hit execute, and got two rows back. SQL Server 2012. What version are you running?
SQL Server 2008
Please don't go. The drones need you. They look up to you.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:30 PM
Points: 5,235,
Visits: 7,038
|
|
Thomas Abraham (5/16/2012)
Hugo Kornelis (5/16/2012)No idea what went wrong. I copied and pasted the code above, hit execute, and got two rows back. SQL Server 2012. What version are you running? SQL Server 2008
The only way I can reproduce what you are seeing, both on SQL Server 2008 R2 (I don't have 2008 vanilla) and on SQL Server 2012, is by setting the SET XACT_ABORT option to ON. (It is OFF by default). Are you running this from a connection where you previously executed a SET XACT_ABORT ON command? Or from a client that implicitly emits this command upon connecting?
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 5:02 AM
Points: 1,149,
Visits: 1,451
|
|
Hugo Kornelis (5/16/2012)The only way I can reproduce what you are seeing, both on SQL Server 2008 R2 (I don't have 2008 vanilla) and on SQL Server 2012, is by setting the SET XACT_ABORT option to ON. (It is OFF by default). Are you running this from a connection where you previously executed a SET XACT_ABORT ON command? Or from a client that implicitly emits this command upon connecting?
I was using a fresh connect that does not emit this command. Is there a command on the order of sp_configure that I can run to verify?
Please don't go. The drones need you. They look up to you.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:30 PM
Points: 5,235,
Visits: 7,038
|
|
Thomas Abraham (5/16/2012)
Hugo Kornelis (5/16/2012)The only way I can reproduce what you are seeing, both on SQL Server 2008 R2 (I don't have 2008 vanilla) and on SQL Server 2012, is by setting the SET XACT_ABORT option to ON. (It is OFF by default). Are you running this from a connection where you previously executed a SET XACT_ABORT ON command? Or from a client that implicitly emits this command upon connecting? I was using a fresh connect that does not emit this command. Is there a command on the order of sp_configure that I can run to verify?
According to this article, you can check the current setting of SET XACT_ABORT by running SELECT 16384 & @@OPTIONS; - if the result is 16384, it is on; if it's 0, the option is off.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|