Several ways to restore data in SQL server:
1. Naturally, the recovery method of backup is backup. This method is the safest and most reliable method and is also very simple to operate. Just select restore in the enterprise manager of sql server. That's it.
It can also be done using T-SQL:
RESTORE DATABASE test FROM DISK = ‘c:mssql7 ackup est.bak’
Of course this is for file recovery, if it is device recovery, it is also possible.
2. But sometimes, the SQL server is paralyzed when we are not prepared, and sometimes it is caused by the paralysis of NT. (At this time, Doufu still has the portrait of Gates on the wall. (I bought a few tomatoes), what should I do? At this time, we can only use the system stored procedures provided in t-sql of sql server:
sp_atach_db
Here is a simple example:
sp_attach_db @dbname = N'pubs',
@ filename1 = N'c:mssql7datapubs.mdf',
@filename2 = N'c:mssql7datapubs_log.ldf'
This method should be said to have a high success rate, but in practice I heard that this is the case Finally, the database becomes read-only, and there is nothing you can do about it. If there is only mdf and no ldf file, you can use sp_attach_single_file
sp_attach_single_file_db @dbname = 'pubs', @physname = 'c:mssql7datapubs.mdf'
This method is originally used to reverse the sp_deatach operation, but It can still be used successfully.