Drop Me!

I was trying to get rid of all the objects (tables, procedures, views) in my database and whipped up this little script and while it is far from perfect it is well worth sharing. . .

SELECT
 CASE WHEN type = 'P' THEN 'DROP PROCEDURE ' + name
      WHEN type = 'U' THEN 'DROP TABLE ' + name
   WHEN type = 'V' THEN 'DROP VIEW ' + name
      WHEN type = 'FN' THEN 'DROP FUNCTION ' + name
    ELSE '' END AS dropSQL, *
FROM sys.objects
WHERE type != 'S' AND type != 'IT' AND type != 'SQ'

Published Saturday, April 12, 2008 6:03 PM by sweisfeld
Filed under:

Comments

No Comments