Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of SQL Server doubtful, suspicious and recovering situations

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

SQL Server doubt, suspicious, recovery and other situation analysis, in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Error sometimes when you restart the database service, you will find that some databases are being restored, doubtful, suspicious, and so on. DBA will be very nervous at this time. Here are some methods that have been proved in practice. After a restart of the database service, the database shows that it is recovering, and after a long time it is still in this state, and the offline time cannot be too long, so I think of a method, that is, to stop the database service, copy the data files mdf and ldf, and delete the ldf file. According to previous experience, it seems that mdf can be used to restore the database without ldf. Creating a database of the same name, stopping the database service, overwriting the mdf file, and then starting the database service is still in a suspicious state. It is impossible to attach a database using mdf, and an error is reported all the time.

Second, the first step to solve the problem is to use scripts for database recovery. The code is as follows:-- DataBaseName is the repaired data name USE MASTER GO SP_CONFIGURE 'ALLOW UPDATES',1 RECONFIGURE WITH OVERRIDE GO ALTER DATABASE [DataBaseName] SET EMERGENCY GO sp_dboption' DataBaseName',' single user', 'true' GO DBCC CHECKDB (' DataBaseName','REPAIR_ALLOW_DATA_LOSS') GO ALTER DATABASE [DataBaseName] SET ONLINE GO sp_configure 'allow updates', 0 reconfigure with override GO sp_dboption' DataBaseName',' single user', 'false' GO

SQL explanation:

1) use the specified value to force reconfiguration: (1, 0 indicates true or false) sp_configure 'allow updates', 1 reconfigure with override

2) set to a state of emergency: alter database DataBaseName set emergency

3) set to single-user mode: alter database [DataBaseName] set single_user or: Sp_dboption 'DataBaseName',' single user', 'true'

4) fix the error found: DBCC CHECKDB ('DataBaseName','REPAIR_ALLOW_DATA_LOSS')

5) set to online, online: ALTER DATABASE [DataBaseName] SET ONLINE

Method 2: this method has not been tried yet, you can try it. The code is as follows: CREATE DATABASE DataBaseName ON (FILENAME ='D:\ DataBase\ Name.mdf') FOR ATTACH_REBUILD_LOG; GO

This is the end of the answers to the questions about SQL Server doubt, suspicion, recovery and so on. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report