sql server修改資料庫名稱

2021-09-14 06:05:48 字數 2201 閱讀 4348

use master

go

----------------修改資料庫名稱-----------------

alter database hroa_i set single_user with rollback immediate

goexec master..sp_renamedb 'hroa_i','hp_oa'

goalter database hp_oa set multi_user

go-----------------2. 修改資料庫邏輯檔案名稱-----------------------------------

alter database hp_oa set single_user with rollback immediate

goalter database hp_oa modify file (name=n'hroa_i', newname=n'hp_oa')

goalter database hp_oa modify file (name=n'hroa_i_log', newname=n'hp_oa_log')

goalter database hp_oa set multi_user

go------------------------------------修改資料庫物理檔名稱之前先開啟xp_cmdshell支援---------------------------------------

use master

gosp_configure 'show advanced options',1

goreconfigure with override

gosp_configure 'xp_cmdshell', 1

goreconfigure with override

go------------------- 重新命名資料庫物理檔名稱-------

alter database hp_oa set offline with rollback immediate

go---d:\rj\mssqlserver\sql server\mssql11.mssqlserver\mssql\data

--d:\rj\mssqlserver\sql server\mssql11.mssqlserver\mssql\data

exec xp_cmdshell 'rename "d:\rj\mssqlserver\sql server\mssql11.mssqlserver\mssql\data\hroa_i.mdf", "hp_oa.mdf"'

goexec xp_cmdshell 'rename "d:\rj\mssqlserver\sql server\mssql11.mssqlserver\mssql\data\hroa_i_log.ldf", "hp_oa_log.ldf"'

go--- 將資料庫邏輯名稱指向新的物理檔案,並將資料庫online

alter database hp_oa modify file (name =hp_oa, filename = 'd:\rj\mssqlserver\sql server\mssql11.mssqlserver\mssql\data\hp_oa.mdf')

goalter database hp_oa modify file (name =hp_oa_log, filename = 'd:\rj\mssqlserver\sql server\mssql11.mssqlserver\mssql\data\hp_oa_log.ldf')

goalter database hp_oa set online

---檢視全部修改完成後的資料庫情況

select name as [logical name], physical_name as [db file path],type_desc as [file type],

state_desc as [state] from sys.master_files

where database_id = db_id(n'hp_oa')

go------step 8 : 關閉xp_cmdshell支援

sp_configure 'xp_cmdshell', 0

goreconfigure with override

gosp_configure 'show advanced options',0

goreconfigure with override

go

SQL Server 修改資料庫

檢視資料庫資訊execute sp helpdb northwind刪除資料庫 包括其中所有資料檔案,在不使用本資料庫的狀態下才能執行。drop database northwind修改資料庫名alter database northwind modify name northwind 000增添資...

mysql修改資料庫名

bin bash 2015.08.10 mysql資料庫改名,官方沒有直接修改資料庫名稱的命令 只有通過修改表名方式實現 source etc profile 載入系統環境變數 source bash profile 載入使用者環境變數 set o nounset 引用未初始化變數時退出 mysql...

C 資料庫SQLServer查詢 修改資料

今天又得寫乙個資料庫sql server讀寫的小工具,主要是涉及到一些簡單的操作,沒什麼技術含量。public static sqlconnection conn static void main string args 資料庫連線 private static void connectiondb ...