东京热无码高清|亚洲区欧洲区综合区视频区|91爱爱电影视频精品激情久久天堂|精品孕妇一区二区三区

首頁(yè) 服務(wù) 產(chǎn)品 文檔 關(guān)于

sqlserver刪除指定字符的數(shù)據(jù)庫(kù)

刪除庫(kù)名包含dw_的數(shù)據(jù)庫(kù)

if object_id('tempdb..#dbToDelete') is not null?

? ? drop table #dbToDelete
if object_id('tempdb..#databaseName') is not null?
? ? drop table #databaseName
declare @dbToDelete table(name varchar(50))
declare @databaseName varchar(100)

insert into @dbToDelete select name from sys.databases where name like '%dw_%'

--刪除指定字符開(kāi)頭,把前面的%號(hào)刪除掉

while exists(select name from @dbToDelete)
begin
?
? ? select top 1 @databaseName=name from @dbToDelete
?
? ? if exists(select * from sys.databases where name = @databaseName)
? ? begin
? ? ? ? print 'dropping databse: '+@databaseName
?
? ? ? ? --強(qiáng)制刪除所有符合條件的實(shí)例
? ? ? ? ? exec('
? ? ? ? use master
? ? ? ? ALTER DATABASE ' + @databaseName +' SET SINGLE_USER WITH ROLLBACK IMMEDIATE
? ? ? ? drop database '+@databaseName)
? ? ? ??
? ? end
? ? ?
? ? delete from @dbToDelete where name = @databaseName
end