StevensNet.com

...Because someone's gotta tell the story...

Blogs

To return to the main Blog List, click Full Blog Listing.

Tags

SharePoint
SQL
Technical

Recovering a SQL database via T-SQL

Friday, January 8, 2016 in Technical Articles (Views: 1565)

So, first post of the year, and wouldn't you know - a late night database issue. My (of all things) SharePoint Config da?tabase was coming up suspect. What to do? Well, here's some TSQL that may help, if you need to recover a database:

USE master
GO
ALTER DATABASE SharePoint_Config SET EMERGENCY
GO
DBCC CHECKDB (SharePoint_Config)
GO
ALTER DATABASE SharePoint_Config SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
DBCC CHECKDB (SharePoint_Config, REPAIR_ALLOW_DATA_LOSS)
GO
ALTER DATABASE SharePoint_Config SET MULTI_USER
GO

Of course, replace SharePoint_Config with your database name. This will put your DB into emergency mode (you will be able to query it at that point), and then ince you run DBCC the second time, the database hopefully will be repaired. The last step, alter database, will make it useable to the system again fully. I recommend a reboot after it's all said and done.

This works fine (done this before) with suspect databases. If you've experienced a hardware failure, like a disk especially, don't expect these things to work - just hope you have a SQL backup.

 

Related Blogs You May Be Interested In:


To leave a comment, please log in and/or register.