Friday, February 17, 2012

Error severity

Hi,
I want to write this SQL script
--
create table table1(
ID_TABLE1 varchar(15) not null
constraint PK_TABLE1 primary key clustered
(ID_TABLE1)
)
IF @.@.ERROR <> 0
BEGIN
print 'Error create table1'
END
--
The problem is when there is a 'create error', the code
print 'Error ...' is not executed because the error's
severity is too high and the script stops.
Is it possible to trap the default error ? When there is a
create error, I want that's the @.@.error is initialized and
the test is executed.
Thanks in advance for your help
Antoine (F-Paris)
MSSQL 7 & MSSQL 2000If the error is severe enough it will stop the batch and you can not trap it
within the batch. You would have to check for the error where you call the
batch. If your using something like ADO, sql server will report an error
that you can see in the errors collection.
Andrew J. Kelly
SQL Server MVP
"Antoine C." <acazedev@.libertysurfXXX.fr> wrote in message
news:11da01c3df60$d4f02bf0$a401280a@.phx.gbl...
quote:

> Hi,
> I want to write this SQL script
> --
> create table table1(
> ID_TABLE1 varchar(15) not null
> constraint PK_TABLE1 primary key clustered
> (ID_TABLE1)
> )
> IF @.@.ERROR <> 0
> BEGIN
> print 'Error create table1'
> END
> --
> The problem is when there is a 'create error', the code
> print 'Error ...' is not executed because the error's
> severity is too high and the script stops.
> Is it possible to trap the default error ? When there is a
> create error, I want that's the @.@.error is initialized and
> the test is executed.
> Thanks in advance for your help
> Antoine (F-Paris)
> MSSQL 7 & MSSQL 2000
|||
quote:

>--Original Message--
>If the error is severe enough it will stop the batch
> and you can not trap itwithin the batch.
> You would have to check for the error where you call the
>batch.
>--

Thank you for the quick answer Andrew.
Bye

No comments:

Post a Comment