-- Attach a database
Sp_attach_db 'database name', 'database full path', 'database log full Path'
Go
Use Database Name
-- Specify the default database before adding a login
Exec sp_addlogin 'login name', 'Password', 'database name'
Go
-- Grant this logon permission to access the database
Exec sp_adduser 'username', 'username', 'db _ owner'
Go
-- Modify the logical file name (data) of the database)
Alter database new
Modify file (name = 'old _ data', newname = 'new _ data ')
Go
-- Modify the logical file name (log) of the database)
Alter database new
Modify file (name = 'old _ log', newname = 'new _ log ')
Go
Copy the above files to the SQL query analyzer, and modify the relevant name. The only drawback is that you can change the logical file name in the last two steps (in fact, you can do it without changing it ), you need to know what the previous name was. Generally, you may not know it. You only need to manually append it (not the real append, as long as you see this logical name, you can exit ), then write it on the top and press F5 to execute it. This will be depressing. I used to append the SQL statement for convenience, so it will be troublesome. If you have a better solution, I hope you will not be enlightened.