validate if table exists while selecting and inserting SQL Server -


hello have dynamic query like

set  @template = 'select x x,... temporaltable from' + @table_name  

then execute it

exec (@template) 
  • how validate if temporaltable exists, if so, drop it?

use information schema or sp_help function.

i prefer information schema since it's sql ansi , can port code other databases:

select count(1)   information_schema.tables   table_name = 'temporaltable'; 

sys.tables sqlserver specific option similar inforamtion schema can explore.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -