Hi all,
I'm using the following code in sql server 2005.
BEGIN TRANSACTION;
CREATE TABLE dbo.MyTable
(
idLang int NOT NULL IDENTITY (1, 1),
codeLang nvarchar(4) NOT NULL
) ON [PRIMARY];
IF @@ERROR = 0
BEGIN
PRINT 'before_commit';
COMMIT TRANSACTION;
PRINT 'after_commit';
END
ELSE
BEGIN
PRINT 'before_rollback';
ROLLBACK TRANSACTION;
PRINT 'after_rollback';
END
GO
1 - Display when MyTable doesn't exist (no error case) :
before_commit
after_commit
=> OK
2 - Display when MyTable exists (error case) :
'There is already an object named 'MyTable' in the database.'
=> Why the "else" statement is not executed ? (no print, no rollback)
I know the alternative with try-catch but i'd like to understand this strange case...
Thanks !