Link to home
Start Free TrialLog in
Avatar of Mr_Shaw
Mr_Shaw

asked on

SQL TRY/CATCH testing for existence.

I am reading Microsoft SQL Server 2008 - Database Development book for example 70-433.

On page 155 (in the NOTE TRAPPING ERRORS) it states that "you cannot use TRY...CATCH block to test for an objects existence".

I put this to the test and the TRY did pass control to the CATCH. Here is my code. Can anybody explain this to me...Thanks.

CREATE TABLE dbo.test
(
ID INT NOT NULL PRIMARY KEY
)

BEGIN TRY
CREATE TABLE dbo.test
(
ID INT NOT NULL PRIMARY KEY
)
END TRY
BEGIN CATCH
PRINT 'Table cannot be created'
END CATCH
ASKER CERTIFIED SOLUTION
Avatar of Ryan McCauley
Ryan McCauley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw
Mr_Shaw

ASKER

thanks