Feedback:

Add IF EXISTS syntax to DROP TABLE, ie. DROP TABLE IF EXISTS #list to "stop" exceptions

This would be so useful (and I think) easy to implement...

13 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    anonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    4 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • AdminEdgar Sherman (Admin, advantage) commented  ·   ·  Flag as inappropriate

        @AzzaAzza69
        It works on free tables. Two gotchas with sp_gettables. 1) The tableNamePattern is case sensitive. 2) don't add the # when looking for temp tables (see KB Item 091124-2232 for a more complete explanation)

      • AzzaAzza69 commented  ·   ·  Flag as inappropriate

        Neither of the above methods (sp_GetTables or SELECT...from system.tables) work for the non-data dictionary connection method!

      • AdminEdgar Sherman (Admin, advantage) commented  ·   ·  Flag as inappropriate

        This should work already. At least it works for me in 9.1. One possible gotcha would be temp tables as they are not added to system.tables. In this case you can use sp_GetTables stored procedure.

      • synack commented  ·   ·  Flag as inappropriate

        if exists (select name from system.tables where name ='test') then
        drop table test;
        end if;

      Feedback and Knowledge Base