问题:
sql server 2005 之后 文件状态变为了7,DEFUNCT(僵死状态)
问题原因:
一般都是因为一些不合法的操作引起的 如以下:
CREATE DATABASE TestGOALTER DATABASE [Test] ADD FILEGROUP [TestFG]GOALTER DATABASE [Test] ADD FILE ( NAME = N'TestFile', FILENAME = N'C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.SQL2008R2\MSSQL\DATA\TestFile.ndf', SIZE = 3072KB , FILEGROWTH = 1024KB ) TO FILEGROUP [TestFG]GO--ok at this point you set it offlineALTER DATABASE Test MODIFY FILE (NAME = TestFile, OFFLINE);SELECT state_desc,* FROM Test.sys.database_files;GO ALTER DATABASE Test MODIFY FILE (NAME = TestFile, OFFLINE);GOALTER DATABASE [Test] REMOVE FILEGROUP [TestFG]GOALTER DATABASE [Test] REMOVE FILE [TestFile]GOSELECT state_desc,* FROM Test.sys.database_files;
解决方法:
使用-m启动服务,使用DAC连接,使用一下代码修改系统表。之前可能要配置 sp_configure 中的 allow update参数。
UPDATE Test.sys.sysprufiles set filestate = 6 where fileid = 3;UPDATE master.sys.sysbrickfiles set filestate = 6 where dbid = db_id('Test') and fileid = 3; checkpoint
正常启动服务,现在文件正处于offline 状态,修改为online,并删除文件和文件组。若数据文件丢失或备份丢失,那么就没办法online了,这个问题还需要深入研究
RESTORE DATABASE test FILE='TestFile' WITH recoverygoALTER DATABASE [Test] REMOVE FILE [TestFile]goALTER DATABASE [Test] REMOVE FILEGROUP [TestFG]GO