在MS SQLSERVER中一直有这样的问题,SQLSERVER的状态"置疑",我们先来分析一下SQLSERVER数据库"置疑"的原因:
1.错误的删除日志;
2.硬件(HD)损坏,造成日志和数据文件写错误;
3.硬盘的空间不够,比如日志文件过大;
解决办法:
这是最简单的办法是有数据库的全备份,然后恢复即可.
步骤:
1. 删除原始的数据库:
USE MASTER
GO
DROP DATABASE DB_SUEPECT
2.建立同名的数据库:
USE master
GO
CREATE DATABASE DB_SUSPECT
ON
( NAME = DBNAME_DAT,
FILENAME = 'C:',
SIZE = 10,
FILEGROWTH = 5 )
LOG ON
( NAME = 'DBNAME_LOG',
FILENAME = 'g:',
SIZE = 5MB,
FILEGROWTH = 5MB )
GO
3.恢复数据库:
RESTORE DATABASE DB_SUSPECT
FROM DBNAME_BACKUP.DAT
4.数据库完整性检测:
DBCC CHECKDB('DB_SUSPECT')
5.重新启动MSSQLSERVER服务.
如果没有全备份,那就要用一些特殊的方法:
1.设置数据库为紧急模式
Use Master
GO
sp_configure 'allow updates', 1
reconfigure with override
GO
UPDATE sysdatabases SET status = 32768 where name = 'DB_SUSPECT'
GO
2.停掉SQL Server服务:
NET STOP MSSQLSERVER
3.把原始数据库的数据文件DBNAME_DAT.MDF,DBNAME_LOG.LDF移走:
4.启动SQL Server服务:
NET START MSSQLSERVER
5.重新建立一个同名的数据库DB_SUSPECT;
USE master
GO
CREATE DATABASE DB_SUSPECT
ON
( NAME = DBNAME_DAT,
FILENAME = 'C:',
SIZE = 10,
FILEGROWTH = 5 )
LOG ON
( NAME = 'DBNAME_LOG',
FILENAME = 'g:',
SIZE = 5MB,
FILEGROWTH = 5MB )
GO
6.设置数据库运行在单用户的模式:
USE MASTER
GO
ALTER DATABASE DB_SUSPECT SET SINGLE_USER
GO
7.停掉SQL服务:
NET STOP MSSQLSERVER
8.把原来的数据文件再覆盖回来:
9.启动SQL Server服务:
NET START MSSQLSERVER
10.重新设置SQLSERVER的状态:
USE MASTER
GO
EXEC sp_resetstatus "DB_SUSPECT"
11.数据库完整性检测:
DBCC CHECKDB('DB_SUSPECT')
12.恢复数据库为多用户模式:
USE MASTER
GO
ALTER DATABASE DB_SUSPECT SET MULTI_USER
GO
13.恢复SQLSERVER原始的配置:
USE MATER
GO
UPDATE sysdatabases SET status = 4194320 where name = 'DB_SUSPECT'
GO
14.配置SQLSERVER不允许更新系统表:
USE MASTER
GO
sp_configure 'allow updates', 0
reconfigure with override
GO
15.重新启动MSSQLSERVER服务:
最好重新启动操作系统
16.备份数据库:
可以通过SQLSERVER企业管理器或T-SQL.需要备份MASTER和DB_SUSPECT
补充一点,如果用DOMAIN/USER时,要注意对.MDF.LDF的所在目录的权限.
====================================================== --before running any script, run the following to set the master database to allow updates USE master GO sp_configure 'allow updates', 1 GO RECONFIGURE WITH OVERRIDE GO --Run the following script UPDATE master..sysdatabases SET status = status ^ 256 WHERE name = 'Database_Name' --Run the following script exec SP_resetstatus Database_Name --stop and start the MSDTC at this stage --After the procedure is created, immediately disable updates to the system tables: exec sp_configure 'allow updates', 0 GO RECONFIGURE WITH OVERRIDE GO ===================================== |
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。