代码改变世界

附加数据库

2009-11-05 21:31  观海看云  阅读(169)  评论(0编辑  收藏  举报
-- 解决方法:
--
假设数据库名为:Test
--
先创建一个同样的数据库Test
--
停掉server服务,用旧的数据文件覆盖新创建的文件(只要mdf就可以)。
--
启动server服务
--
运行以下命令
sp_configure 'allow',1
go

reconfigure with override
go

update sysdatabases set status=32768 where name='Test'
go

dbcc rebuild_log('Test','D:\database\Test_Log.ldf')
go

update sysdatabases set status=0 where name='Test'
go

sp_configure  
'allow',0   
go

reconfigure with override
go

dbcc checkdb('Test')
go

--若发现有错误,还要进一步找出出错的地方,可以先检查
--
DBCC CHECKTABLE (sysobjects)
--
DBCC CHECKTABLE (sysindexes)
--
DBCC CHECKTABLE (syscolumns )
--
DBCC CHECKTABLE (systypes)