Generating SQL scripts to multiple tables in SQL Server 2005

Just now, I face on the task of creating an SQL query that will be executed on 20 tables. This is very tedious if we try to manually input the table name every after query execution. Luckily, SQL Server have a table named Information_Schema.TABLES that can output table names on the current database!

So, my query to generate a script for all the tables, I just hit this query to the window:

   1: SELECT 'drop table ' + table_name
   2: FROM Information_Schema.TABLES
   3: WHERE table_name NOT IN ('cleanvoters', 'DuplicateVoters', 'IncompleteVoters')

Result:

   1: drop table Caloocan1st
   2: drop table Caloocan2nd
   3: drop table LasPinas
   4: drop table Makati1st
   5: drop table Makati2nd
   6: drop table Malabon
   7: drop table Mandaluyong
   8: drop table Manila1st

So easy and very handy script.