SqlServer数据库修复Suspect的问题
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SqlServer数据库修复Suspect的问题相关的知识,希望对你有一定的参考价值。
-- 进入maser数据库
USE master
GO
-- 启用系统表更新
sp_configure ‘allow updates‘, 1
GO
RECONFIGURE WITH OVERRIDE
GO
-- 关闭 c_nzz 数据库的置疑标志
sp_resetstatus c_nzz
GO
-- sp_resetstatus 存储过程代码
IF EXISTS ( SELECT * from sysobjects where name = ‘sp_resetstatus‘ )
DROP PROCEDURE sp_resetstatus
GO
CREATE PROC sp_resetstatus @dbname varchar(30) AS
DECLARE @msg varchar(80)
IF @@trancount > 0
BEGIN
PRINT ‘Can‘‘t run sp_resetstatus from within a transaction.‘
RETURN (1)
END
IF suser_id() != 1
BEGIN
SELECT @msg = ‘You must be the System Administrator (SA)‘
SELECT @msg = @msg + ‘ to execute this procedure.‘
RETURN (1)
END
IF (SELECT COUNT(*) FROM master..sysdatabases
WHERE name = @dbname) != 1
BEGIN
SELECT @msg = ‘Database ‘ + @dbname + ‘ does not exist!‘
PRINT @msg
RETURN (1)
END
IF (SELECT COUNT(*) FROM master..sysdatabases
WHERE name = @dbname AND status & 256 = 256) != 1
BEGIN
PRINT ‘sp_resetstatus can only be run on suspect databases.‘
RETURN (1)
END
BEGIN TRAN
UPDATE master..sysdatabases SET status = status ^ 256
WHERE name = @dbname
IF @@error != 0 OR @@rowcount != 1
ROLLBACK TRAN
ELSE
BEGIN
COMMIT TRAN
SELECT @msg = ‘Database ‘ + @dbname + ‘ status reset!‘
PRINT @msg
PRINT ‘‘
PRINT ‘WARNING: You must reboot SQL Server prior to ‘
PRINT ‘ accessing this database!‘
PRINT ‘‘
END
GO
-- 禁用系统表更新
sp_configure ‘allow updates‘, 0
GO
RECONFIGURE WITH OVERRIDE
GO
https://bbs.csdn.net/topics/10304111
以上是关于SqlServer数据库修复Suspect的问题的主要内容,如果未能解决你的问题,请参考以下文章
MS SQL恢复操作已将该数据库标记为 suspect,质疑问题有效解决
无法打开数据库‘Data’.恢复操作已将数据库标记为SUSPECT。