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...
4 comments
-
AdminEdgar Sherman
(Admin, advantage)
commented
@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
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
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
if exists (select name from system.tables where name ='test') then
drop table test;
end if;