1. Import the script
EXEC sp_attach_db @dbname = 'yhzm',
@filename1 = 'd:\jspyhzm.mdf',
@filename2 = 'd:\jspyhzm_log.ldf'
2. What should I do if Microsoft SQL Server deletes the database and prompts an error
If the database being debugged needs to be deleted, there is a connection to it. At this time, an error will be deleted.
We can see the delete error message here, because the database is in use, error: 3702
Solution: Tick Close Connection in the lower left corner
3. Error when attaching database: Unable to open physical file XXX.mdf". Operating system error 5: "5 (Access Denied.)"
The reason is that the database permissions cannot read the files under the path.
Solution 1: Use windows authentication for the database, and transplant the attached database to the root directory, that is, the DATA directory of MSSQL.
Solution 2: Windows authentication, then change the permissions of the .mdf file and .ldf file to be attached, select the .mdf file ----> Right click -----> Security ------> Authenticated Users-- -->Edit---->Security Control Allow,
In the same way, change the log file and then attach the database.