[SQL Server] renaming a database

Source: Internet
Author: User
Tags management studio microsoft sql server management studio sql server management sql server management studio
Create a new database accounting with the default configuration
Use master;
Go

Create Database accounting;
Go
Method 1: select database> F2 from the object Resource Manager on Microsoft SQL Server Management Studio (SSMs), or right-click Database> rename image 1. Method 2: write SQL statements
Use master;
Go

Exec sp_renamedb n 'accounting', N 'financial ';
Go

However, we opened the default storage path of the database and found that the names of MDF and LDF have not changed.

Figure 2

You may want to detach the database and rename the financial. MDF, financial_log.ldf, and reattach the database directly to the data files and log files.

Figure 3

"An error occurred while attaching the database." How can this problem be solved?

Click the message to view the error details.

Figure 4

Unable to open the physical file accounting. MDF description after renaming, the database does not recognize the name we changed.

By viewing the "Financial" database details, we found that the content of the current file path field is incorrect, and the message field also showed that the file could not be found.

Therefore, we make the following changes:

Click OK. The database is attached!

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.