Results 1 to 4 of 4

Thread: How to skip steps in SQL code

  1. #1
    Join Date
    Feb 2010
    Posts
    4

    How to skip steps in SQL code

    Hi,

    I have a SQL code where there are steps like creation of table follwed by delete data from the table. For the first time when we run the code, the create table runs well. For the second time if the table in the create script already exist how do we check that and skip that statement to go to the next step which is DELETE step.

    For eg:

    Create table x;
    delete x;

    IF table x already exists what should be done to check if it already exist and go to the next DELETE step.

    Thanks,
    Saran.

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Try something like:

    IF OBJECT_ID('table x') IS NULL
    Create table x
    Else
    ....

  3. #3
    Join Date
    Feb 2010
    Posts
    4
    Thank u.
    Does Null mean the table does not contain data or the table is not present?
    My question is if the table is not present create else go to next step. Its not about the data present in table. Help me out on this.

    Thanks,
    Saran.

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    Table is not present.

Posting Permissions

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