Jump to content

Database Name As Parameter / Variable


Badg3r1977
 Share

Recommended Posts

Database Name as Parameter / Variable Hi im using SQL Server Management Studio 2008 addition and im trying to specify a database name for a fix database script we run: ALTER DATABASE MyDatabase SET EMERGENCYDBCC checkdb('MyDatabase')ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATEDBCC CheckDB ('MyDatabase', REPAIR_ALLOW_DATA_LOSS)ALTER DATABASE MyDatabase SET MULTI_USER When I try to replace MyDatabase with a variable the code will not run! Does anybody have any ideas? FYI: Im just learning SQL; please treat me like an idiot! Thanks all

Link to comment
Share on other sites

Its neither; run SQL Server Management Studio, connect to the database, select new query (a new query window open that points to the currently selected database). I would then just copy the above into the query window and hit execute. I currently have to specify the database name 5 times; I would like to only have to specify it once in a variable. I cant create stored procedures as its an enterprise database and I don’t own it! I just (in this case) need to repair suspect databases!

Edited by Badg3r1977
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...