Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

by mistake one Script on Master Expand / Collapse
Author
Message
Posted Monday, June 1, 2009 1:35 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, March 24, 2014 1:16 AM
Points: 347, Visits: 412
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.



Post #726452
Posted Monday, June 1, 2009 2:06 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 9:18 PM
Points: 317, Visits: 408
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.
Post #726458
Posted Tuesday, June 2, 2009 11:10 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 7:27 AM
Points: 1,186, Visits: 1,973
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




(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.
Post #727599
Posted Tuesday, June 2, 2009 12:58 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 9:18 PM
Points: 317, Visits: 408
Nice tip, John! I'm going to use it myself
Post #727661
Posted Tuesday, June 2, 2009 1:09 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 7:27 AM
Points: 1,186, Visits: 1,973
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.



(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.
Post #727669
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse