The example in this article describes how T-SQL statements modify SQL Server database logical names, database names, and physical names. Share to everyone for your reference, specific as follows:
To change the physical file name of the MSSQL database SQL statement
Note: In the activity Monitor, make sure there are no processes connected to the database you want to rename!!!!!!!!!!!!!!!!!!!!
The SQL statement is as follows
use master--Change the logical name ALTER DATABASE yqblog MODIFY FILE (name= ' Yqblogaa ', newname= ' Yqblog ')-- Go ALTER db yqblog MODIFY FILE (name= ' Yqblogaa_log ', newname= ' Yqblog_log ')--go--Change database name EXEC sys.sp_renamedb @dbname = ' Yqblogaa ',--sysname @newname = ' yqblog ' Go--detach database exec sp_detach_db yqblog go--open xp_cmdshell feature exec Sp_configu Re ' show advanced Options ', 1 go reconfigure to EXEC sp_configure ' xp_cmdshell ', 1 go reconfigure go------Change physical name (note: Do not show in the path exec xp_cmdshell ' ren C:\Users\Administrator\Desktop\YQBlogAA.mdf yqblog.mdf '------Change physical name exec xp_cmdshell ' ren c:\u Sers\administrator\desktop\yqblogaa_log.ldf yqblog_log.ldf '--go------Reattach EXEC sp_attach_db @dbname = N ' Yqblog ', @fil ename1 = N ' C:\Users\Administrator\Desktop\YQBlog.mdf ', @filename2 = N ' C:\Users\Administrator\Desktop\YQBlog_log.ldf '
More about SQL Server-related content readers can view the site topics: SQL Server stored procedure tips, SQL Server query operations tips, SQL Server indexing operations tips, SQL Server Paging technology summary and SQL Server Common Functions Summary
I hope this article will help you with your SQL Server database program.