SQL server 2008 数据库置疑的处理办法
SQL Server 2008数据库被标记为可疑的解决方法
SQL Server 2008数据库被标记为可疑的解决方法2011-08-23 16:36 佚名火魔网字号:T | T本文我们主要介绍了SQL Server 2008数据库被标记为可疑时的解决方法,希望能够对您有所帮助。
AD:在使用SQL Server 2008数据库时发现数据库被标记为可疑,查看网上的资料终于找到了解决办法,接下来我们就来介绍解决方法。
解决方法:当数据库发生这种操作故障时,可以按如下操作步骤可解决此方法,打开数据库里的Sql 查询编辑器窗口,运行以下的命令。
1、修改数据库为紧急模式ALTER DATABASE Zhangxing SET EMERGENCY2、使数据库变为单用户模式ALTER DATABASE Zhangxing SET SINGLE_USER3、修复数据库日志重新生成,此命令检查的分配,结构,逻辑完整性和所有数据库中的对象错误。
当您指定“REPAIR_ALLOW_DATA_LOSS”作为DBCC CHECKDB命令参数,该程序将检查和修复报告的错误。
但是,这些修复可能会导致一些数据丢失。
DBCC CheckDB (Zhangxing, REPAIR_ALLOW_DATA_LOSS)4、使数据库变回为多用户模式ALTER DATABASE Zhangxing SET MULTI_USER也可以这样做:1:重新建立一个,一样的数据库,路径名称,文件都一样。
2:关掉SQL Server服务;3:把源文件COPY过来;4:开启SQL Server服务,这样问题同样就解决了。
以上就是SQL Server 2008数据库被标记为可疑的两种解决方法,本文就介绍到这里了,希望本次的介绍能够对您有所收获!今天在客户服务器的数据库里面的一个数据库突然出现了点问题,数据库状态变为可疑了,这个问题之前有见过,虽然解决了,但并没有把过程和解决方法记录下来,决定这次记录在博客园里,方便自己也方便他人在遇到这个问题的时候,能快速解决!废话不多说,先说说数据库变可疑的原因:在进行些不正常操作如数据库在读写时而无故停止数据库,从而导致Sql Serv er 数据库不正常中断,当再次打开数据库时会发现某些数据库会被标记为“可疑”(suspect),即在数据库名旁加上了黄色的惊叹号,这时数据库就不能再被打开了,但数据库的结构及数据内容都还是存在的。
SQLSERVER2008 数据库可疑的解决步骤
1 把问题数据库备份后直接删除停掉SQLSERVER服务,把服务器上出问题的数据库, 假设名称为 ErrorDB的数据库文件及日志文件备份到其他目录,然后直接将其删除,把其数据库文件及日志文件也删除2 新建同名数据库启动SQLSERVER服务,新建同名数据库ErrorDB,文件目录和日志和原来一致3 用备份的数据库文件替换新的数据库文件停掉SQLSERVER服务,把备份的数据库文件替换新的数据库文件(只替换数据库文件,不替换日志文件)启动SQLSERVER服务,打开数据库,这时数据库应该是不能访问的-------------------设置应急模式、单用户模式、检查修复数据,取消单用户模式----------------------4 将数据库设置为应急状态alter database ErrorDB set emergency执行后,为了保险起见,重新停止、开启的SQLSERVER服务再打开数据库,已经可以看到里面的内容了,如表,视图,存储过程等数据库名称后有紧急标志,能看到数据库结构,但无法进行备份等操作5 将数据库设置为单用户模式ALTER DATABASE ErrorDB SET SINGLE_USER6 对数据库进行检查修复dbcc checkdb(EIMSDb,REPAIR_ALLOW_DATA_LOSS)dbcc checkdb(EIMSDb,REPAIR_REBUILD)操作后,仍然停止启动SQLSERVER服务(不确定是否需要,我只是为了想无干扰查看执行后的数据库状况)重新打开数据库,已经是正常状态了,没有应急提示了7 取消单用户模式exec sp_dboption EIMSDb, N'single', N'false'至此,数据库恢复完毕,对数据库进行BAK。
SQL数据库置疑解决方案(原因、预防、修复)附图
S Q L数据库置疑解决方案(原因、预防、修复)附图-CAL-FENGHAI-(2020YEAR-YICAI)_JINGBIANSQL数据库置疑解决方案一、数据库置疑产生的原因1、SQL Server所在分区空间是否够?数据库文件大小是否达到最大文件限制?FAT32的格式只支持4G以内的文件。
2、数据库文件损坏或被非正常删除时出现这种情况。
3、病毒防火墙的扫描也会引起数据库置疑。
4、当SQL Server启动时,将会尝试获得对数据库文件的排他访问权,如果此时该文件被其他程序占用,或者遗失,数据库将会被标记为置疑。
5、电脑非法关机也会造成数据库置疑。
6、电脑磁盘有坏道有可能造成数据库置疑。
二、数据库置疑的预防1、数据库存放的盘符,空间是否够大,经常检查盘符的空间。
2、数据库存放的盘符的格式设置为NTFS格式。
3、进行病毒清除时,尽量把SQL服务停掉,再进行检查。
4、尽量减少非正常关机。
5、建议客户购买后备电源。
6、给客户实施软件之后一定要做好自动备份。
7、建议客户每隔一定时间手动备份一次。
三、数据库置疑的修复1、正常的备份、SQL数据库恢复方式正常方式下,我们要备份一个数据库,首先要先将该数据库从运行的数据服务器中断开,或者停掉整个数据库服务器,然后复制文件。
卸下数据库的命令:Sp_detach_db 数据库名连接数据库的命令:Sp_attach_db或者sp_attach_single_file_dbs_attach_db [@dbname =] ′dbname′, [@filename1 =] ′filename_n′ [,...16]sp_attach_single_file_db [@dbname =] ′dbname′, [@physname =] ′physical_name′使用此方法可以正确恢复SQL Sever7.0和SQL Server 2000的数据库文件,要点是备份的时候一定要将mdf和ldf两个文件都备份下来,mdf文件是数据库数据文件,ldf是数据库日志文件。
SQL数据库置疑的解决方法
SQL2000数据库置疑的解决方法首先,在任何操作之前,必须要备份数据库(重要)一、分离数据库1、点击“程序》Microsoft SQL Server》企业管理》”,打开企业管理器2、展开服务器组,然后展开服务器,选中要分离的数据库3、点击鼠标右键“所有任务》分离数据库”,出现如下窗口4、点击确定,该选定的数据库就被分离。
5.分离后,把原数据库里面.MDF(主数据文件).LDF(事务日志文件)这两个文件复制到目标盘下,例:D盘下注意事项,只有“使用本数据库的连接”数为0时,该数据库才能分离。
所以分离数据库时尽量断开所有对要分离数据库操作的连接,如果还有连接数据库的程序,会出现数据库的连接状态窗口,显示正在连接此数据库的机器以及名称,点击清除按钮将从服务器强制断开现有的连接。
二、附加数据库1、在附加数据库之前,首先要移动数据库文件在附加数据库之前,您必须将与数据库关联的 .MDF(主数据文件).LDF(事务日志文件)这两个文件复制到目标硬盘下,或是同一服务器的不同硬盘目录下。
这两个文件一般位于C:\Program Files\Microsoft SQL Server\MSSQL\Data目录下。
2、点击“程序》Microsoft SQL Server》企业管理》”,打开企业管理器3、展开服务器组,然后展开服务器4、右击"数据库",然后选择“所有任务》附加数据库”,弹出窗口5、输入要附加的数据库的MDF名称。
如果不确定文件位于何处,单击浏览("...")搜索。
若要确保指定的 MDF 文件正确,请单击"验证"。
在"附加为"框内,输入数据库的名称。
数据库名称不能与任何现有数据库名称相同。
指定数据库的所有者6、单击"确定"按钮。
新附加的数据库的数据库节点即创建在"数据库"文件夹中重启双机1.此时数据库分离,附加完成,必须重启一次双机修复置疑1,双机重启后,数据库置疑下面所有修复置疑的语法,在没有特别提到时,默认数据库都请选择(Master)数据库)2,修复置疑(必须在SQL的查询分析器中才能进行数据修复置疑工作)A、打开查询分析器,当数据置疑之后在查询分析器中是看不到置疑的数据库名称的,所以进入查询分析器之后,所选数据库默认(Master)数据库即可。
SQL置疑数据库处理方法
SQL置疑数据库处理方法:1.新建一个同名的数据库。
2.停掉sql server(注意不要分离数据库)。
3.用原数据库(质疑的那个)的数据文件覆盖掉这个新建的数据库文件。
(以上1、2、3步骤是针对把质疑数据库文件放到另外的计算机处理的情况,如果就在本机处理,可以省略,但在处理前一定要注意备份数据库文件。
)4.再重启sql server。
5.此时打开企业管理器时会出现置疑,先不管,执行下面的语句(注意修改其中的数据库名)。
USE MASTERGOSP_CONFIGURE 'ALLOW UPDATES',1 RECONFIGURE WITH OVERRIDEGOUPDATE SYSDATABASES SET STATUS =32768 WHERE NAME='置疑的数据库名'Gosp_dboption '置疑的数据库名', 'single user', 'true'GoDBCC CHECKDB('置疑的数据库名')Goupdate sysdatabases set status =28 where name='置疑的数据库名'Gosp_configure 'allow updates', 0 reconfigure with overrideGosp_dboption '置疑的数据库名', 'single user', 'false'Go6.完成后一般就可以访问数据库中的数据了;这时,数据库本身一般还要问题,解决办法是利用数据库的脚本创建一个新的数据库,并将数据导进去就行了,或者把数据库导成一个新库来代替旧库,先把数据导出,然后重启计算机后再导入就OK了。
步骤如下:企业管理器--右键你的数据库--所有任务--导出数据(导入数据)--目标标数据库选择新建--选择"在两个sql数据库之间复制对象和数据"--把"包含扩展属性"选上,其他的根据需要选择--最后完成。
解决SQLServer 2008 数据库质疑
解决SQLServer2008数据库质疑(挂起)问题Step1.执行语句,改变数据库状态EXEC SP_RESETSTATUS'Your DBName'GOStep2:重置数据库状态之后,我们就应该对质疑的数据库执行DBCC CHECKDB命令,查看下为什么数据库会出现质疑状态.DBCC CHECKDB('Your DBName')WITH NO_INFOMSGS,ALL_ERRORMSGSGoStep3:找到原因之后,那么就好解决了.看报错信息中,已说明了PK中存在重复值.首先,将每个索引的脚本导出为sql文件.之后再将表中主键栏位里的duplicate的行删除掉Step4:现在最好再立即执行下DBCC CHECKDB命令确认下是否还有错误信息.之后确认没有,那么再将之前索引的脚本创建进去.Step5:在Index创建完毕之后,立即执行下DBCC CHECKDB命令确认下是否还有错误信息.确认无误,那么就需要立即对数据库执行一次完全备份作业.针对SQL2000挂起情况进行修复Step1:设置数据库为紧急模式Use Mastersp_configure'allow updates',1reconfigure with overrideGOUPDATE sysdatabases SET status=32768where name='TEST'GOStep2:停止数据库服务通过Windows服务或者SQLServer管理器.Step3:把原始数据库的数据文件DBNAME_DAT.MDF,DBNAME_LOG.LDF移走Step4:启动SQL Server服务Step5.重新建立一个同名的数据库TEST;USE masterGOCREATE DATABASE TESTON(NAME=DBNAME_DAT,FILENAME='C:',SIZE=10,FILEGROWTH=5)LOG ON(NAME='DBNAME_LOG',FILENAME='g:',SIZE=5MB,FILEGROWTH=5MB)GOStep6:设置数据库运行在单用户的模式:USE MASTERGOALTER DATABASE TEST SET SINGLE_USERGOStep7:停掉SQL服务Step8:把原来的数据文件再覆盖回来Step9:启动SQL Server服务Step10:设置数据库为紧急模式Use Mastersp_configure'allow updates',1reconfigure with overrideGOUPDATE sysdatabases SET status=32768where name='TEST'GOStep11:修复数据库错误DBCC CHECKDB('TEST',REPAIR_ALLOW_DATA_LOSS)Step12.恢复数据库为多用户模式USE MASTERGOALTER DATABASE TEST SET MULTI_USERGOStep13.恢复SQLSERVER原始的配置USE MATERGOUPDATE sysdatabases SET status=4194320where name='TEST'GOStep14:配置SQLSERVER不允许更新系统表USE MASTERGOsp_configure'allow updates',0reconfigure with overrideGOStep15:重新启动MSSQLSERVER服务,最好重新启动操作系统.Step16:备份数据库特殊情况:不知道为什么,质疑修复后,数据库恢复正常了。
解决SQLSERVER2008系统数据库MSDB“可疑”的方法
解决SQL Server2008 msdb可疑的数据库的方法请参考文章ProblemDue to a recent rebuild of the master DATAbase for a SQL Server instance, I now need to RESTore the msdb and model databases. In this tip we walk through the process that you need to follow to restore the model and msdb databases successfully.SolutionBefore we get started, let's quickly discuss what the msdb and model databases are used for.● The msdb database contains scheduled jobs, alerts and backup history therefore a proper backup plan should be implemented for the msdb system database.● The model database is the blue print for creating any new user database for that particular instance of SQL Server. DBAs can modify the model database with whatever settings that are required and when a new user database is created it will reflect the configuration of the model database. If the model database has been modified then it should be backed up.Hence both the msdb and model DATAbases may need to be recovered in scenarios like DATAbase corruption, a rebuild of the master database or after a new server configuration. The RESTore process of msdb or model demands additional considerations than that of a user databases. The RESTore process may get complicated if versions are not tracked andexclusive access is not ensured in all aspects. In the next sections we will go through the restore process for the msdb and model databases.Note: this exercise was performed on SQL Server 2005, but the same rules would also be applied on SQL Server 2005 and onwards.Backup msdbUse the following command to create a full backup of the msdb database using T-SQL commands. You will need to modify the script to use a valid backup path. You can perform the same process for the model database as well.--Script 1: Create backup of msdbUSE [master]GOBACKUP DATABASE [msdb]TO DISK = N'E:\MSDB_Backup.Bak'WITH INIT,NAME = N'msdb Backup for MSSQLTips Demo'GOAfter this is complete we have a full backup that can be RESTored.Prepare for RESToreTo ensure we have a smooth restore we need to follow these steps.● Get the version of destination server● Get the version of source server on which the backup was created● Match the versions for the source and destination servers● Ensure exclusive access to the DATAbaseThe term source server here refers to the server on which the backup was created and destination server is where the restore will occur.Get version of destination serverThe versions of SQL Server need to be the same for the source and destination when restoring the msdb or model database. If the versions for the source and destination servers do not match then the restorewill fail as shown below:Msg 3168, Level 16, State 1, Line 1The backup of the system DATAbase on the device E:\MSDB_Backup.Bak cannot be RESTored because it was created by a different version of the server (9.00.1399) than this server (9.00.5000).Msg 3013, Level 16, State 1, Line 1RESTORE DATABASE is terminating abnormally.In the case of a mismatch, the version of SQL Server for the destination needs to be manipulated by installing or removing service packs.Here are the three ways to get the version for the SQL Server database engine.Using SSMS Object ExplorerConnect to a SQL Server instance through SSMS and find the SQL Server version in object explorer as shown below.Using SERVERPROPERTY system functionThe SERVERPROPERTY system function can be used for retrieving SQL Server version information to get edition and service pack information.Using @@VersionThe SQL Server version can also be retrieved by using @@Version. It can be used in a simple select statement as shown below.Get version of source server on which backup was createdNow we need to get the version of the source server on which the backup was created. The best way to do this is to get the information from the backup file itself as shown below using the RESTORE HEADERONLY command.-- Script 2: Get information of backup fileRESTORE HEADERONLYFROM DISK = N'E:\MSDB_Backup.Bak'GOAbove is the partial output from the command and we can see the SoftwareVersionMajor, SoftwareVersionMinor andSoftwareVersionBuild. These three values equate to the output from the other commands we look at earlier.Match the versions of source and destination serverIn our case we have version 9.0.5000 which matches both the source and destination servers. If this is not the case then apply or remove service packs on the destination server to match the source server. Once both versions are the same then we are ready to go further with the process.Following is a mapping of version codes for SQL Server 2005 and onwards from Microsoft SQL Server support.Ensure exclusive accessExclusive access for the DATAbase is required just like RESToring any database, but for the msdb it is slightly more demanding. In the case of msdb we also have to consider the SQL Agent service. If the SQL Server agent service is running then exclusive access can not be achieved. Below we can see that the SQL Agent service is running by querying sys.sysprocesses.So for msdb we need to stop the SQL Agent service to make sure we can get exclusive access. This can be done by right clicking on SQL Server Agent and selecting Stop.RESTore msdbAt this point our requirements are fulfilled and we are ready to perform the restore. Execute the following command for the restore process.--Script 3: Restore msdbUSE masterGORESTORE DATABASE [msdb]FROM DISK = N'E:\MSDB_Backup.Bak'WITH REPLACEGOThe msdb database is now restored as shown below. Now we need to put the database back in multi user (if this was changed) and start the SQL Server agent service.The same requirements and process also work for the model database except that the SQL Agent service is not an issue.Another thing to note is that you can restore msdb and model databases across editions such as Express, Developer, Standard and Enterprise. You only need to be concerned that the versions are the same.Next Steps● As part of best practices, go through your various phases of a disaster recovery process. Manipulating system DATAbases is an integral part of disaster recovery.● Click here to read a tip about getting exclusive access of SQL Server databases● Click here to read a tip about system databases in SQL Server● Click here to read details about versions and releases of SQL Server● Click here to read about using SERVERPROPERTY● Click here to read about using @@Version。
SQL数据库置疑的解决办法
SQL数据库置疑的解决办法数据库管理 2008-11-14 14:24:58 阅读435 评论2字号:大中小以下为恢复方法:-------------------------------------------------------------------------------步骤1:创建一个新的数据库,命名为原来数据库的名字。
步骤2:停止SQL Server步骤3:把老数据库的MDF文件替换新数据库的相应的MDF文件,并把LDF文件删除。
步骤4:重新启动SQL Server服务,然后运行如下命令:Use MasteGosp_configure 'allow updates', 1reconfigure with overrideGobegin tranupdate sysdatabases set status = 32768where name = 'db_name'--Verify one row is updated before committin gcommit tran步骤5:停止SQL然后重新启动SQL Server服务,然后运行如下命令:DBCC TRACEON(3604)DBCC REBUILD_LOG('db_name','c:\mssql7\data\dbxxx_3.ldf')Go步骤6:停止SQL然后重新启动SQL Server服务,然后运行:use masterupdate sysdatabases set status = 8 wh ere name = 'db_name'Gosp_configue 'allow updates', 0reconfigure with overridego步骤7:运行dbcc checkdb(db_name) 检查数据库的完整性恢复数据库后,即使貌似恢复了,说不定中间也会有错误,最合理的解决办法是,利用当前恢复的数据库的脚本创建一个新的数据库,并将数据导进去,然后使用新的数据库替代恢复的数据库。
sql server 2008 数据库中遇到的常见问题及解决问题办法
一、数据库无法连接到.解决方法:需要在服务器名称处输入【.\sqlexpress】单击连接二、无法连接到.\sqlexpress 用户‘sa’登陆失败。
(Microsoft SQL Server,错误:18456)解决方法:(1、SQL Server Management Studio Express(简写SSMS))(2、SQL Server 配置管理器/SQL Server Configuration Manager(简写SSCM))1.打开数据库,用windows身份连接数据库,登陆后,右键选择“属性”2.左侧选择“安全性”,选中右侧的“SQL Server和Windows身份验证模式”以启用混合登陆模式。
3.选择“连接”,勾选“允许远程连接此服务器”,然后点“确定”4.展开“安全性”->“登陆名”->“sa”,右键“属性”5.左侧选择“常规”,右侧选择“SQL Server身份验证”,并设置密码6.选择“状态”,选中“启用”,点击“确定”7.右击数据库选择“方面”在下拉列表中选择“服务器配置”在下面选择“RemoteAccessEnabled”属性设置为“True”,点击“确定”。
8.数据库(SSMS)已设置完毕,先退出,再用sa登录,成功即表示sa 账户已经启用9.下面开始配置SSCM,选中左侧的“SQL Server服务”,确保右侧的“SQL Server”以及“SQLServer Browser”正在运行10.以下为英文版本界面。
右侧的TCP/IP默认是“Disabled”,双击打开设置面板将其修改为“Enabled”11.选择“IP Addersses”选项卡,设置端口“1433”12.将“Client Protocols”的“TCP/IP”也修改为“Enabled”配置完成重新启动SQL Server2008.三、附加数据库出现的问题解决方法:这个是SQL Server 登录账户没有权限,修改方法如下:开始- SQL 2008 - 配置工具- SQL Server配置管理器选择SQL Server 服务,双击SQL Server (SQLEXPRESS)将内置账户修改为LocalSystem 重启服务后重试附加,成功后将这里再修改回去四、附加数据库出现错误解决办法:按以下方式修改你的SQL的MDF和LDF属性就可以了,选择你的文件(两种文件均要修改为一样的权限)MDF文件:文件右键>>属性>>安全>>编辑>>添加>>高级>>立即查找>>在搜索结果中选择:Authenticated Users>>确定>>确定>>确定>>MDF文件属性对话框>>在组或用户名列表框中选择:Authenticated Users>>高级>>更改权限>>编辑>>选中“安全控制”>>确定>>确定>>确定>>确定。
SQL数据库置疑解决方案(原因、预防、修复)附图
SQL数据库置疑解决方案一、数据库置疑产生的原因1、SQL Server所在分区空间是否够?数据库文件大小是否达到最大文件限制?FAT32的格式只支持4G以内的文件。
2、数据库文件损坏或被非正常删除时出现这种情况。
3、病毒防火墙的扫描也会引起数据库置疑。
4、当SQL Server启动时,将会尝试获得对数据库文件的排他访问权,如果此时该文件被其他程序占用,或者遗失,数据库将会被标记为置疑。
5、电脑非法关机也会造成数据库置疑。
6、电脑磁盘有坏道有可能造成数据库置疑。
二、数据库置疑的预防1、数据库存放的盘符,空间是否够大,经常检查盘符的空间。
2、数据库存放的盘符的格式设置为NTFS格式。
3、进行病毒清除时,尽量把SQL服务停掉,再进行检查。
4、尽量减少非正常关机。
5、建议客户购买后备电源。
页脚内容16、给客户实施软件之后一定要做好自动备份。
7、建议客户每隔一定时间手动备份一次。
三、数据库置疑的修复1、正常的备份、SQL数据库恢复方式正常方式下,我们要备份一个数据库,首先要先将该数据库从运行的数据服务器中断开,或者停掉整个数据库服务器,然后复制文件。
卸下数据库的命令:Sp_detach_db 数据库名连接数据库的命令:Sp_attach_db或者sp_attach_single_file_dbs_attach_db [@dbname =] ′dbname′, [@filename1 =] ′filename_n′[,...16]sp_attach_single_file_db [@dbname =] ′dbname′, [@physname =] ′physical_name′使用此方法可以正确恢复SQL Sever7.0和SQL Server 2000的数据库文件,要点是备份的时候一定要将mdf和ldf两个文件都备份下来,mdf文件是数据库数据文件,ldf是数据库日志文件。
例子:假设数据库为pdm,其数据文件为pdm_data.mdf,日志文件为pdm_log.ldf。
解决SQLSERVER 2008系统数据库MSDB “可疑”的方法
解决SQL Server2008 msdb可疑的数据库的方法请参考文章/sqlservertip/2571/restoring-sql-server-system-databases-msdb-and-model/ProblemDue to a recent rebuild of the master database for a SQL Server instance, I now need to restore the msdb and model databases. In this tip we walk through the process that you need to follow to restore the model and msdb databases successfully.SolutionBefore we get started, let's quickly discuss what the msdb and model databases are used for.∙The msdb database contains scheduled jobs, alerts and backup history therefore a proper backup plan should be implemented for the msdb system database.∙The model database is the blue print for creating any new user database for that particular instance of SQL Server. DBAs can modify the model database with whateversettings that are required and when a new user database is created it will reflect theconfiguration of the model database. If the model database has been modified then itshould be backed up.Hence both the msdb and model databases may need to be recovered in scenarios like database corruption, a rebuild of the master database or after a new server configuration. The restore process of msdb or model demands additional considerations than that of a user databases. The restore process may get complicated if versions are not tracked and exclusive access is not ensured in all aspects. In the next sections we will go through the restore process for the msdb and model databases.Note: this exercise was performed on SQL Server 2005, but the same rules would also be applied on SQL Server 2005 and onwards.Backup msdbUse the following command to create a full backup of the msdb database using T-SQL commands. You will need to modify the script to use a validbackup path. You can perform the same process for the model database as well.--Script 1: Create backup of msdbUSE [master]GOBACKUP DATABASE [msdb]TO DISK = N'E:\MSDB_Backup.Bak'WITH INIT,NAME = N'msdb Backup for MSSQLTips Demo'GOAfter this is complete we have a full backup that can be restored.Prepare for restoreTo ensure we have a smooth restore we need to follow these steps.∙Get the version of destination server∙Get the version of source server on which the backup was created∙Match the versions for the source and destination servers∙Ensure exclusive access to the databaseThe term source server here refers to the server on which the backup was created and destination server is where the restore will occur.Get version of destination serverThe versions of SQL Server need to be the same for the source and destination when restoring the msdb or model database. If the versions for the source and destination servers do not match then the restore will fail as shown below:Msg 3168, Level 16, State 1, Line 1The backup of the system database on the device E:\MSDB_Backup.Bak cannot be restored because it was created by a different version of the server (9.00.1399) than this server (9.00.5000).Msg 3013, Level 16, State 1, Line 1RESTORE DATABASE is terminating abnormally.In the case of a mismatch, the version of SQL Server for the destination needs to be manipulated by installing or removing service packs.Here are the three ways to get the version for the SQL Server database engine.Using SSMS Object ExplorerConnect to a SQL Server instance through SSMS and find the SQL Server version in object explorer as shown below.Using SERVERPROPERTY system functionThe SERVERPROPERTY system function can be used for retrieving SQL Server version information to get edition and service pack information.Using @@VersionThe SQL Server version can also be retrieved by using @@Version. It can be used in a simple select statement as shown below.Get version of source server on which backup was createdNow we need to get the version of the source server on which the backup was created. The best way to do this is to get the information from the backup file itself as shown below using the RESTORE HEADERONLY command.-- Script 2: Get information of backup fileRESTORE HEADERONLYFROM DISK = N'E:\MSDB_Backup.Bak'GOAbove is the partial output from the command and we can see the SoftwareVersionMajor, SoftwareVersionMinor andSoftwareVersionBuild. These three values equate to the output from the other commands we look at earlier.Match the versions of source and destination serverIn our case we have version 9.0.5000 which matches both the source and destination servers. If this is not the case then apply or remove service packs on the destination server to match the source server. Once both versions are the same then we are ready to go further with the process.Following is a mapping of version codes for SQL Server 2005 and onwards from Microsoft SQL Server support.Ensure exclusive accessExclusive access for the database is required just like restoring any database, but for the msdb it is slightly more demanding. In the case of msdb we also have to consider the SQL Agent service. If the SQL Server agent service is running then exclusive access can not be achieved. Below we can see that the SQL Agent service is running by queryingsys.sysprocesses.So for msdb we need to stop the SQL Agent service to make sure we can get exclusive access. This can be done by right clicking on SQL Server Agent and selecting Stop.Restore msdbAt this point our requirements are fulfilled and we are ready to perform the restore. Execute the following command for the restore process.--Script 3: Restore msdbUSE masterGORESTORE DATABASE [msdb]FROM DISK = N'E:\MSDB_Backup.Bak'WITH REPLACEGOThe msdb database is now restored as shown below. Now we need to put the database back in multi user (if this was changed) and start the SQL Server agent service.The same requirements and process also work for the model database except that the SQL Agent service is not an issue.Another thing to note is that you can restore msdb and model databases across editions such as Express, Developer, Standard and Enterprise. You only need to be concerned that the versions are the same.Next Steps∙As part of best practices, go through your various phases of a disaster recovery process.Manipulating system databases is an integral part of disaster recovery.∙Click here to read a tip about getting exclusive access of SQL Server databases∙Click here to read a tip about system databases in SQL Server∙Click here to read details about versions and releases of SQL Server∙Click here to read about using SERVERPROPERTY∙Click here to read about using @@Version。
数据库“置疑”该怎么处理
以下方法为处理数据库日志文件错误导致的数据库置疑,如果无法处理。
可使用DBCC直接修复或者BCP方式修复,请参照社区发布的DBCC修复或者BCP修复或者直接在知识库中输入关键词“DBCC”或者“BCP”进行搜索。
步骤1:停止SQL服务管理器,将原数据文件拷贝,使用思迅数据库安装程序创建一个新的数据库。
步骤2:停止SQL Server步骤3:把老数据库的MDF文件替换新数据库的相应的MDF文件,并把LDF文件删除。
步骤4:重新启动SQL Server服务,然后运行如下命令:Use MasterGosp_configure 'allow updates', 1reconfigure with overrideGobegin tranupdate sysdatabases set status = 32768 where name = 'hbposv7'--Verify one row is updated before committingcommit tran步骤5:停止SQL然后重新启动SQL Server服务,然后运行如下命令:DBCC TRACEON(3604)DBCC REBUILD_LOG('db_name','C:\Program Files\Microsoft SQLServer\MSSQL\Data\hbposv7_log.ldf')Go步骤6:停止SQL然后重新启动SQL Server服务,然后运行:use masterupdate sysdatabases set status = 8 where name = 'hbposv7'Gosp_configure 'allow updates', 0reconfigure with overrideGo步骤7:运行dbcc checkdb(hbposv7) 检查数据库的完整性注:都要替换成真实的数据库名字。
SQL数据库置疑解决方法
SQL数据库置疑解决方法
一、SQL数据库置疑
1.数据库安全问题
为了保护数据库,需要确保数据库中的信息不被恶意攻击、篡改或盗窃,从而避免造成不可挽回的损失。
2.数据库可靠性问题
可靠性是指数据库系统必须在不同的时间片段可靠运行,即使是在发生系统故障的情况下,用户也能够一直获取服务。
只有数据库系统可靠性良好,才能够实现数据库系统的高安全性要求。
3.数据库性能问题
要满足用户的需求,必须保证数据库服务器能够达到最佳性能,避免出现数据库访问运行缓慢的问题,以及查询数据库时出现的查询延时、查询次数多等问题。
4.数据库维护问题
数据库系统是一个复杂的系统,在日常运行中难免会出现数据库系统故障、业务变更需求等情况。
数据库系统维护对于保证系统可靠性,提高系统性能至关重要。
1.数据库安全问题
(1)做好安全设置,为数据库设置正确的授权,只允许拥有访问权限的用户进行访问,并设置访问日志,记录访问和更改的用户,以及操作的时间等信息。
(2)定期备份数据库,将备份数据存放到安全的位置。
数据库置疑的解决方法
数据库置疑的解决方法
首先,当我们发现数据库出现问题时,我们需要及时排查可能的原因。
我们可
以通过查看数据库的日志文件和错误日志,来了解数据库最近的运行情况和可能出现的错误信息。
此外,我们还可以通过数据库管理工具来检查数据库的表结构、索引情况以及数据完整性,以确定问题的具体表现和可能的原因。
其次,针对不同的数据库问题,我们需要采取不同的解决方法。
比如,当数据
库出现性能问题时,我们可以通过优化查询语句、增加索引、分析表结构等方式来提升数据库的性能;当数据库出现数据丢失或损坏的情况时,我们可以通过备份恢复数据、修复表结构、使用数据恢复工具等方式来恢复数据的完整性。
此外,我们还需要重视数据库的安全性和稳定性。
我们可以通过加强数据库的
访问控制、定期备份数据、定期维护数据库等方式来保障数据库的安全性和稳定性。
同时,我们还可以考虑使用数据库集群、数据库镜像、数据库分区等方式来提升数据库的可用性和容错性。
最后,我们需要不断学习和积累数据库维护和故障排除的经验,以便更好地应
对各种数据库问题。
我们可以通过阅读相关的书籍和文档、参加培训课程、积极参与技术社区的讨论等方式来不断提升自己的数据库维护和故障排除能力。
总之,数据库置疑的解决方法需要我们及时排查问题、针对不同问题采取不同
的解决方法、重视数据库的安全性和稳定性,以及不断学习和积累经验。
希望以上内容能够帮助大家更好地解决数据库置疑的问题,确保数据库的正常运行和数据的完整性。
数据库质疑修复总结ForSQLS...
数据库质疑修复总结ForSQLS...1 前言本文的步骤基于以下条件:1. SQL Server可以启动。
2. 数据库没有做有效的备份。
3. 当前用户有Sysadmin权限。
数据库质疑的原因会有多种多样,不同的suspect采用的步骤也会有所不同,以下的步骤不能适用所有的情况,但包括了一些基本的步骤。
数据库suspect是指数据库内部处于不一致的状态,很有可能会有数据丢失。
我们推荐您从“好的数据库备份”恢复。
我们这里所指的“好的数据库备份”是指:1. 在做数据库备份之前,您检查过DBCC CHECKDB没有错误。
2. 备份之后的数据库没有更改,或者更改可以忽略。
在做任何修复操作之前,请务必备份.mdf/.ndf以及.ldf文件。
2 SQL Server 2000修复步骤如果没有“好的数据库备份”,我们不能保证没有数据丢失。
以下是恢复suspect数据库(SQL Server 2000)的一般方法,供您参考。
同时在操作下列步骤之前,您可以备份质疑数据库的MDF、NDF、LDF文件,以便以下步骤恢复失败时能够回滚到原来的状态。
1. 在查询分析器中,运行如下命令将数据库置于紧急模式。
Sp_configure 'allow update', 1GoReconfigure with overrideGoBegin TranUpdate master..sysdatabases set status = 32768 where name ='<DatabaseName>’Commit Tran--此处<DatabaseName>需要替代成您出问题的数据库名字。
--以下同GoSelect * from sysdatabases--检查数据库状态是否已经变成 32768Go2. 重启SQL Server服务。
3. 如果第二步中重启服务,数据库再次进入suspect模式,请设置数据库紧急模式,使用BCP方式导出数据。
sql05 08置疑解决
关于门店数据库SQLSERVER2000/2005/2008置疑问题处理方法SQL Server2008置疑数据库解决方法1.首先确认已经备份了.mdf和.ldf文件。
2. 在SQL Server中新建一个同名的数据库,然后停止SQL Server服务。
3. 用原有的.mdf和.ldf文件覆盖新建数据库对应的.mdf和.ldf文件。
4. 重新启动SQL Server服务,这是应该会看到这个数据库处于置疑(Suspect)状态。
5. 在SQL查询分析器中执行以下命令,以允许更新系统表:use mastergosp_configure "allow updates",1reconfigurewithoverridego6. 将这个数据库置为紧急模式:update sysdatabases set status = 32768 where name="db_name"go7. 使用DBCC CHECKDB命令检查数据库中的错误:DBCC CHECKDB("db_name")GO8. 如果DBCC CHECKDB命令失败,请转至第10步,否则先将数据库置为单用户模式,再尝试对其进行修复:sp_dboption "db_name","singleuser","true"DBCCCHECKDB("db_name",REPAIR_ALLOW_DATA_LOSS)GO如果在执行DBCCCHECKDB("db_name",REPAIR_ALLOW_DATA_LOSS)命令时提示说数据库未处于单用户模式状态的话,则重新启动SQLServer服务,然后继续尝试。
9. 如果DBCCCHECKDB("db_name",REPAIR_ALLOW_DATA_LOSS)命令失败,请转至第10步,否则若成功修复了数据库中的错误:重新执行DBCC CHECKDB("db_name")命令,确认数据库中已没有错误存在。
SQL server 2008 数据库置疑的处理办法
SQL server 2008 数据库置疑的处理办法1 把问题数据库备份后直接删除停掉SQLSERVER服务,把服务器上出问题的数据库, 假设名称为ErrorDB的数据库文件及日志文件备份到其他目录,然后直接将其删除,把其数据库文件及日志文件也删除2 新建同名数据库启动SQLSERVER服务,新建同名数据库ErrorDB,文件目录和日志和原来一致3 用备份的数据库文件替换新的数据库文件停掉SQLSERVER服务,把备份的数据库文件替换新的数据库文件(只替换数据库文件,不替换日志文件)启动SQLSERVER服务,打开数据库,这时数据库应该是不能访问的-------------------设置应急模式、单用户模式、检查修复数据,取消单用户模式----------------------4 将数据库设置为应急状态alter database ErrorDB set emergency执行后,为了保险起见,重新停止、开启的SQLSERVER服务再打开数据库,已经可以看到里面的内容了,如表,视图,存储过程等数据库名称后有紧急标志,能看到数据库结构,但无法进行备份等操作5 将数据库设置为单用户模式ALTER DATABASE ErrorDB SET SINGLE_USER6 对数据库进行检查修复dbcc checkdb(EIMSDb,REPAIR_ALLOW_DATA_LOSS)dbcc checkdb(EIMSDb,REPAIR_REBUILD)操作后,仍然停止启动SQLSERVER服务(不确定是否需要,我只是为了想无干扰查看执行后的数据库状况)重新打开数据库,已经是正常状态了,没有应急提示了7 取消单用户模式exec sp_dboption EIMSDb, N'single', N'false'至此,数据库恢复完毕,对数据库进行BAK重启网站,访问正常。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SQL server 2008 数据库置疑的处理办法
1 把问题数据库备份后直接删除
停掉SQLSERVER服务,把服务器上出问题的数据库, 假设名称为ErrorDB的数
据库文件及日志文件备份到其他目录,然后直接将其删除,把其数据库文件及日志
文件也删除
2 新建同名数据库
启动SQLSERVER服务,新建同名数据库ErrorDB,文件目录和日志和原来一致
3 用备份的数据库文件替换新的数据库文件
停掉SQLSERVER服务,把备份的数据库文件替换新的数据库文件(只替换数据库文件,不替换日志文件)
启动SQLSERVER服务,打开数据库,这时数据库应该是不能访问的
-------------------设置应急模式、单用户模式、检查修复数据,取消单用户模式----------------------
4 将数据库设置为应急状态
alter database ErrorDB set emergency
执行后,为了保险起见,重新停止、开启的SQLSERVER服务
再打开数据库,已经可以看到里面的内容了,如表,视图,存储过程等
数据库名称后有紧急标志,能看到数据库结构,但无法进行备份等操作
5 将数据库设置为单用户模式
ALTER DATABASE ErrorDB SET SINGLE_USER
6 对数据库进行检查修复
dbcc checkdb(EIMSDb,REPAIR_ALLOW_DATA_LOSS)
dbcc checkdb(EIMSDb,REPAIR_REBUILD)
操作后,仍然停止启动SQLSERVER服务(不确定是否需要,我只是为了想无干
扰查看执行后的数据库状况)重新打开数据库,已经是正常状态了,没有应
急提示了
7 取消单用户模式
exec sp_dboption EIMSDb, N'single', N'false'
至此,数据库恢复完毕,对数据库进行BAK
重启网站,访问正常。