T-sql語句修改SQL Server數(shù)據(jù)庫邏輯名、數(shù)據(jù)庫名、物理名的方法
本文實例講述了T-sql語句修改SQL Server數(shù)據(jù)庫邏輯名、數(shù)據(jù)庫名、物理名的方法。分享給大家供大家參考,具體如下:
更改MSSQL數(shù)據(jù)庫物理文件名Sql語句的寫法
注意:要在活動監(jiān)視器里面確保沒有進(jìn)程連接你要改名的數(shù)據(jù)庫!!!!!!!!!!!!!!!!!!!!
Sql語句如下
USE master --改邏輯名 ALTER DATABASE YQBlog MODIFY FILE(NAME='YQBlogAA',NEWNAME='YQBlog') -- GO ALTER DATABASE YQBlog MODIFY FILE(NAME='YQBlogAA_log',NEWNAME='YQBlog_log') -- GO --改數(shù)據(jù)庫名 EXEC sys.sp_renamedb @dbname = 'YQBlogAA', -- sysname @newname = 'YQBlog' GO --分離數(shù)據(jù)庫 EXEC sp_detach_db YQBlog GO --打開xp_cmdshell功能 EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO EXEC sp_configure 'xp_cmdshell', 1 GO RECONFIGURE GO ---- --改物理名(注意:路徑中不要出現(xiàn)中文) EXEC xp_cmdshell 'ren C:\Users\Administrator\Desktop\YQBlogAA.mdf YQBlog.mdf' ---- --改物理名 EXEC xp_cmdshell 'ren C:\Users\Administrator\Desktop\YQBlogAA_log.ldf YQBlog_log.ldf' --GO ---- --重新附加 EXEC sp_attach_db @dbname = N'YQBlog', @filename1 = N'C:\Users\Administrator\Desktop\YQBlog.mdf', @filename2 = N'C:\Users\Administrator\Desktop\YQBlog_log.ldf'
更多關(guān)于SQL Server相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《SQL Server存儲過程技巧大全》、《SQL Server查詢操作技巧大全》、《SQL Server索引操作技巧大全》、《SQL Server分頁技術(shù)總結(jié)》及《SQL Server常用函數(shù)匯總》
希望本文所述對大家SQL Server數(shù)據(jù)庫程序設(shè)計有所幫助。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信