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