T-SQL statement to modify the logic name, database name, and physical name of the SQL Server database, t-sqlsql

Source: Internet
Author: User

T-SQL statement to modify the logic name, database name, and physical name of the SQL Server database, t-sqlsql

This example describes how to modify the logical name, database name, and physical name of the SQL Server database using the T-SQL statement. We will share this with you for your reference. The details are as follows:

Change the SQL statement for the physical file name of the MSSQL database

Note: In the activity monitor, make sure that no process is connected to the database you want to rename !!!!!!!!!!!!!!!!!!!!

The SQL statement is as follows:

USE master -- MODIFY the logic name alter database YQBlog modify file (NAME = 'yqblogaa ', NEWNAME = 'yqblog') -- goalter database YQBlog modify file (NAME = 'yqblogaa _ log ', NEWNAME = 'yqblog _ log') -- GO -- change the database name EXEC sys. sp_renamedb @ dbname = 'yqbloga', -- sysname @ newname = 'yqblog' GO -- detach the database EXEC sp_detach_db YQBlogGO -- open the xp_cmdshell function EXEC sp_configure 'show advanced options ', 1 GORECONFIGUREGOEXEC sp_configure 'xp _ Your shell', 1GORECONFIGUREGO ---- change the physical name (Note: Do not show Chinese characters in the path) EXEC xp_your shell 'Ren C: \ Users \ Administrator \ Desktop \ YQBlogAA. mdf YQBlog. mdf '---- -- change the physical name EXEC xp_mongoshell 'Ren C: \ Users \ Administrator \ Desktop \ YQBlogAA_log.ldf yqblog_log.ldf' -- GO ---- re-append EXEC sp_attach_db @ dbname = n' YQBlog ', @ filename1 = n'c: \ Users \ Administrator \ Desktop \ YQBlog. mdf ', @ filename2 = n' C: \ Users \ Administrator \ Desktop \ YQBlog_log.ldf'

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.