SQL SERVER modifies the database name (including modification of the db.mdf name)

Source: Internet
Author: User

Toss SQL SERVER 2012, get a morning to modify the database name, mainly need to modify the name of Db.mdf and Db_log.ldf, finally solved. Write it down here, and change it later, and don't forget it.

Assuming the original database name is DB, the attached database is db.mdf and db_log.ldf.

Need to be changed to DBT, and Dbt.mdf and Dbt_log.ldf.

Steps:

1. First make a backup of the original database (choose Database--right----------), back up the Db.bak file.

2. Right-click the task---restore database, and jump out of the Restore Database window.

3. Select "Source Device", browse, jump out "Specify Backup" dialog box, click Add to find the Db.bak file just backed up, OK.

4. In the Restore Database window, select the backup set for restore to tick the backup set.

5. Select "File" in the "Options page", "Specify the path after the restore and the name Dbt.mdf and dbt_log.ldf (directly change the name)

OK, that is, the modification of the name is completed.

6. Change the physical name of the database file, the physical name of the transaction log

Open SQL Query Analyzer and enter the following code;

ALTER Database name MODIFY file (name= ' current database file physical name ', newname= ' database physical name to change ')

ALTER DATABASE DBT MODIFY FILE (name= ' db ', newname= ' DBT ')

ALTER DATABASE DBT MODIFY FILE (name= ' db_LOG ', newname= ' Dbt_log ')

SQL SERVER modifies the database name (including modification of the db.mdf name)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.