use mastergodeclare
@dbname sysname,
@destpath varchar(256)
declare @db table(
name sysname,
physical_name sysname)
begin try
select
@dbname = 'ff', --input database name
@destpath = 'e:/' --input destination path
--kill database processes
declare @spid varchar(20)
declare curprocess cursor for
select spid
from sys.sysprocesses
where db_name(dbid) = @dbname
open curprocess
fetch next from curprocess into @spid
while @@fetch_status = 0
begin
exec('kill ' + @spid)
fetch next from curprocess
endclose curprocess
deallocate curprocess
--query physical name
insert @db(
name,
physical_name)
select
a.name,
a.physical_name
from sys.master_files a
inner join sys.databases b
on a.database_id = b.database_id
and b.name = @dbname
where a.type <=1
--set offline
exec('alter database ' + @dbname + ' set offline')
--move to dest path
declare
@login_name sysname,
@physical_name sysname,
@temp_name varchar(256)
declare curmove cursor for
select
name,
physical_name
from @db
open curmove
fetch next from curmove into @login_name,@physical_name
while @@fetch_status = 0
begin
set @temp_name = right(@physical_name,charindex('/',reverse(@physical_name)) - 1)
exec('exec xp_cmdshell ''move "' + @physical_name + '" "' + @destpath + '"''')
exec('alter database ' + @dbname + ' modify file ( name = ' + @login_name
+ ', filename = ''' + @destpath + @temp_name + ''')')
fetch next from curmove into @login_name,@physical_name
endclose curmove
deallocate curmove
--set online
exec('alter database ' + @dbname + ' set online')
--show result
select
a.name,
a.physical_name
from sys.master_files a
inner join sys.databases b
on a.database_id = b.database_id
and b.name = @dbname
end try
begin catch
select error_message() as errormessage
end catch
Sqlite資料庫設定密碼小工具
想用sqlite資料庫進行做個小專案,發現sqlite的工具沒有修改密碼功能 我用的工具是sqlitestudio 3.1.1 就度娘了下,找到了這個部落格 那下面就廢話不說,擼袖開幹!亮個像先 新建winform frmmain 新增dll庫 system.data.sqlite.dll 884k...
移動sq 資料庫物理檔案儲存過程
use master godeclare dbname sysname,destpath varchar 256 declare dbtable name sysname,physical name sysname begin tryselect dbname ff input database n...
SQL語句實現移動資料庫檔案
看csdn上看到一朋友寫了乙個 貼個sql小工具 移動資料庫物理檔案 使用是方法是先設定資料庫離線,再移動資料庫檔案,然後修改資料庫的儲存檔案路徑,最後再設定資料庫聯機。這裡我寫的使用的是,先分離資料庫,再移動資料庫檔案,然後再附加新資料庫檔案的方法 usemaster goif object id...