Jump to content

Database Name As Parameter / Variable


Badg3r1977

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!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...