Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2002
    Posts
    3

    Thumbs up Unanswered: DB2 equivalent of If Exists query in MSSQl

    Hi All,
    In MSSQL we use the If Exists query to check whether an object exists before it is dropped. This helps us to Drop the Object only if it exists. I want to run DB2 scripts in the command center and before i create a table i want to drop it, but first check whether it exists. The sysibm.systables Table will provide info about the table. But i do not know how to check it with the if condition. Please let me know if any one of you knows how to do it.

    Thanks,
    Vishrant

  2. #2
    Join Date
    Jun 2002
    Posts
    8

    Re: DB2 equivalent of If Exists query in MSSQl

    begin atomic

    if (exists(select 'A' from syscat.tables where tabname='HELLO')) then
    insert into HELLO values('abc') ;
    end if;
    end @

    works , but

    begin atomic

    if (exists(select 'A' from syscat.tables where tabname='HELLO')) then
    drop table HELLO ;
    end if;
    end @


    doesn't .... Any ideas why ?

    If the second statement is working, Vishrant has the answer ..



    Originally posted by Vishranthp
    Hi All,
    In MSSQL we use the If Exists query to check whether an object exists before it is dropped. This helps us to Drop the Object only if it exists. I want to run DB2 scripts in the command center and before i create a table i want to drop it, but first check whether it exists. The sysibm.systables Table will provide info about the table. But i do not know how to check it with the if condition. Please let me know if any one of you knows how to do it.

    Thanks,
    Vishrant

Posting Permissions

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