by mistake one Script on Master

  • I have maintained 20 database on one server.

    To update all these 20 database I have created one script.

    scripts contains create table and Stored Procedures statements.

    By mistake I have run this script on Master Database.

    Any way to easily DROP all this un neccesary objects from master database.

  • View > Object Explorer Details - select the objects you want to delete, right-click, and delete.

    In future, make sure you have the right execution context before running a script. Next time it might be a DROP TABLE and you're running on Production.

  • Put a safety check at the beginning of your script. We have to do the same thing (i.e., upgrade 100+ databases with a new release). To avoid accidental schema creation or schema upgrade into a "system" database the following is at the start of my script:

    SELECT CAST('Target Database is: ' + DB_NAME() AS VARCHAR(70));

    GO

    IF UPPER(DB_NAME()) IN ('MASTER', 'MODEL', 'MSDB')

    RAISERROR('Invalid database for schema creation.', 16, 1);

    GO


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

  • Nice tip, John! I'm going to use it myself 🙂

  • Randolph Potter (6/2/2009)


    Nice tip, John! I'm going to use it myself 🙂

    You're welcome. It is one of numerous defensive measures that I've implemented. Usually resulting from the school of "hard knocks".

    Just make sure that you use the -b (on error batch abort) switch when you run your script using SQLCMD.


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply