St procedure without exception

  • hi,

    my stored procedure contains a lot of ddl query:

    create proc xxxxx

    as

    CREATE TABLE TAB1 .......

    CREATE TABLE TAB2 .......

    CREATE TABLE TAB3 .......

    .........................

    .........................

    .........................

    .........................

    CREATE TABLE TABn .......

    go

    if a table already exists the stored procedure must exec the next ddl query without raise an exception, it's possible ?

    Thanks, anakin

  • Try This:

    IF NOT EXISTS (SELECT * FROM sysobjects WHERE [Name] = 'TAB1' AND Type = 'U')

    BEGIN

    CREATE TABLE TAB1 ...

    END

    -Dan


    -Dan

  • Or check with

    if object_id('tablename') is null

    begin

    --table name not found create it

    end

  • You might want to consider using the INFORMATION_SCHEMA to reference the database objects. These names are not subject to change.

    HTH

    Steve Hendricks

    MCSD, MCDBA

    AFS Consulting Group

    shendricks@afsconsulting.com

    (949) 588-9800 x15


    Steve Hendricks
    MCSD, MCDBA
    Data Matrix

    shendricks@afsconsulting.com
    (949) 588-9800 x15

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply