DECLARE @Dbname NVARCHAR(50) = 'DBNAME' --Replace to target db name DECLARE @Sql NVARCHAR(MAX) = '' SET @Sql = @Sql+'EXEC sp_resetstatus ['+@Dbname+'];' SET @Sql = @Sql+'ALTER DATABASE ['+@Dbname+'] SET EMERGENCY;' SET @Sql = @Sql+'DBCC CheckDB(['+@Dbname+']);' SET @Sql = @Sql+'ALTER DATABASE ['+@Dbname+'] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;' SET @Sql = @Sql+'DBCC CheckDB(['+@Dbname+'], REPAIR_ALLOW_DATA_LOSS);' SET @Sql = @Sql+'ALTER DATABASE ['+@Dbname+'] SET MULTI_USER;' PRINT @Sql EXEC [sp_executesql] @Sql;參考網站: https://support.managed.com/kb/a398/how-to-repair-a-suspect-database-in-mssql.aspx
在SQL Server中執行下列指令修復資料庫
0 意見:
張貼留言