[SQL Server] Rename database "Go"

Source: Internet
Author: User

Original link: http://www.cnblogs.com/Ryan_j/archive/2011/04/03/2004428.html

Renaming a database is simple, select the database-right--Rename the database

Or

' olddb ',' newdb '

But if you create a new database with the same name, you will get an error indicating that the database already exists.

For example, after the test database is renamed to Test1, a new database named Test will receive an error that already exists in the test database.

To the SQL Server installation directory data, you will find that test.mdf and test_log.ldf already exist. This is actually the original test1 renamed database file, we modified the database name, the database file name has not changed (or should say, test1 or test database file). Well, let's rename the database file, OK!

The database file name cannot be renamed directly because it is in use. Of course, you can stop and rename SQL Server services, and then you open SSMs should be error or let you select a database database file (so the pain of the thing I did not test, because I think this is not the appropriate method).

Or using Ryan's method, detach the database, then rename the database file, and then attach the database, for example, the data and log messages are "not found"

Then you re-select your renamed database file and log, OK.

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.