Change the database name with SQL

Source: Internet
Author: User

today is nothing to learn from the Internet to a SQL little tricks, share with you.

exec sp_renamedb " < original database name > ', ' < New database name > '

then select the statement and press   "F5" Key, the steps are as follows:

first of all, my SQL Server There is a name called " SQL "Database, and now I want to change the name of this database to "Da" ; 1


650) this.width=650; "title=" Figure 1 "style=" Float:none; "alt=" wkiom1wbsgfgvqwnaabnafbp_4w724.jpg "src=" http:/ S3.51cto.com/wyfs02/m00/6e/a6/wkiom1wbsgfgvqwnaabnafbp_4w724.jpg "/>

Figure 1

then open the Query Analyzer and enter the command in the Query window in Query Analyzer. 2:

650) this.width=650; "title=" Figure 2 "style=" Float:none; "alt=" wkiol1wbshfacmsxaaawyti4gxs800.jpg "src=" http:/ S3.51cto.com/wyfs02/m01/6e/a2/wkiol1wbshfacmsxaaawyti4gxs800.jpg "/>

Figure 2

then select the statement and click the "F5" key will display the result in the message window;3

650) this.width=650; "title=" Figure 3 "style=" Float:none; "alt=" wkiom1wbsgeaduwqaabkctmpe5i790.jpg "src=" http:/ S3.51cto.com/wyfs02/m02/6e/a6/wkiom1wbsgeaduwqaabkctmpe5i790.jpg "/>

Figure 3

then we'll refresh our database in the Query Analyzer and we'll see the name of the database "SQL" has become "da";4

650) this.width=650; "title=" Figure 4 "style=" Float:none; "alt=" wkiom1wbsgfhmawzaabb-gsq5yk367.jpg "src=" http:/ S3.51cto.com/wyfs02/m01/6e/a6/wkiom1wbsgfhmawzaabb-gsq5yk367.jpg "/>

Figure 4

the operation to change the database is now complete. But we sometimes have a situation where the following error occurs when executing the above command;5

650) this.width=650; "title=" Figure 5 "style=" Float:none; "alt=" wkiol1wbsheim7yzaabfcsfln3q858.jpg "src=" http:/ S3.51cto.com/wyfs02/m02/6e/a2/wkiol1wbsheim7yzaabfcsfln3q858.jpg "/>

Figure 5

What is the reason for this? To tell you the truth, for the first contact with the database of me, but really I understand, but everything has a solution, my operation is to the Query Analyzer and Enterprise Manager, such as SQL Server program all shut down (especially the service manager), and then open, and re-enter the statement and execute it.







This article is from "a 4S shop webmaster" blog, please be sure to keep this source http://milibin.blog.51cto.com/170812/1662882

Change the database name with SQL

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.