Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004
    Posts
    2

    Smile Unanswered: @@ERROR & CREATE TABLE

    Hi

    I've been looking at scripting some create tables, but want to know if the table created successfully. I've been doing the following:

    DECLARE @ERRCODE INT

    CREATE TABLE x
    SET @ERRCODE = @@ERROR

    This works ok, if there is no erroor. However if I run this again, then obviously I get the error "This object already exists" and the script stops executing.

    Is there a way that I can capture the error using @@ERROR and still let the script run ?

    Thanks in advance

    Mickster

  2. #2
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Well, you shouldn't. "On Error Resume Next" is not present in T-SQL. What you should do is perform a validation for presence of object before attempting to create it.
    Code:
    if objectproperty(object_id('dbo.x'), 'isusertable')=1 drop table dbo.x
     
    create table dbo.x (f1 int, ...)
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  3. #3
    Join Date
    Dec 2004
    Posts
    2

    @@ERROR & CREATE TABLE

    Thanks, but I already understand that I should check for the existance of the object - as stated in my last mail. I want to check the table is being created correctly incase of other events, like permissions, file full, etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •