Delete all databases

Last post 08-28-2008 4:34 AM by Madhivanan. 5 replies.
Page 1 of 1 (6 items)
Active Topics My Discussions Unanswered Sort Posts: Previous Next
  • 08-01-2008 7:19 PM

    Delete all databases

    Does anyone have a good t-sql script to quickly delete several hundred databases?

  • 08-03-2008 11:44 PM In reply to

    • waqar
    • Top 75 Contributor
    • Joined on 03-15-2006
    • Singapore
    • Posts 223

    Re: Delete all databases

     5 min work Wink.

     


    CREATE TABLE AllUserDbs (ID INT IDENTITY(1,1),DBName VARCHAR(MAX))
    INSERT INTO AllUserDbs SELECT [NAME] FROM sys.databases WHERE database_id>4
    DECLARE @J INT
    DECLARE @I INT
    DECLARE @DBNAME VARCHAR(MAX)
    SET @I=1
    SELECT @J=COUNT(*) FROM AllUserDbs
    WHILE @I<=@J
    BEGIN
    SELECT @DBNAME=DBName FROM AllUserDbs WHERE ID=@I
    EXEC ('DROP DATABASE ' + @DBNAME)
    SET @I=@I+1
    END

    ________________________________________________
    Be great in act, as you have been in thought.
  • 08-04-2008 5:10 AM In reply to

    Re: Delete all databases

    mherfkens:

    Does anyone have a good t-sql script to quickly delete several hundred databases?

    several hundred databases or tables?

    Madhivanan

    Failing to plan is Planning to fail
  • 08-04-2008 5:30 AM In reply to

    Re: Delete all databases

    Delete, or hide from view?

  • 08-28-2008 1:49 AM In reply to

    Re: Delete all databases

    SELECT 'DROP DATABASE'+SPACE(1)+name from sysdatabases where dbid>4 , Run this and it will produce the script to drop all the user db's. Then u need to run the output script to drop the databases.

    Cheers,
    Prabhakar
  • 08-28-2008 4:34 AM In reply to

    Re: Delete all databases

    Well. Still I am waiting for replies from OP

    Madhivanan

    Failing to plan is Planning to fail
Page 1 of 1 (6 items)
Active Topics   My Discussions    Unanswered Posts


© 2000 - 2007 vDerivatives Limited All Rights Reserved.