国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

SqlServer強制斷開數據庫已有連接的方法

2024-08-31 00:57:01
字體:
來源:轉載
供稿:網友
在執行建庫腳本時,往往會先將原有的數據庫drop掉,由于SqlServer檢測到有數據連接時禁止執行drop database操作,所以建庫腳本經常執行失敗,為此我們需要一種能強制斷開數據庫已有連接的方法,可以過如下t-sql實現:

復制代碼 代碼如下:


declare @i int declare cur cursor for select spid from sysprocesses where db_name(dbid)= 'Your_Database_Name' open cur fetch next from cur into @i while @@fetch_status=0 begin exec('kill '+@i) fetch next from cur into @i end close cur deallocate cur


我們可以把這條sql寫到建庫的批處理腳本里,放在腳本的開始:

復制代碼 代碼如下:


:: Disconnect existing Fortune database connections
osql -S"%1" -U"%2" -P"%3" -Q"declare @i int declare cur cursor for select spid from sysprocesses where db_name(dbid)= ' Your_Database_Name ' open cur fetch next from cur into @i while @@fetch_status=0 begin exec('kill '+@i) fetch next from cur into @i end close cur deallocate cur"

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凤台县| 米林县| 武安市| 兴仁县| 大冶市| 延吉市| 平凉市| 印江| 陆丰市| 银川市| 建湖县| 固阳县| 宜兴市| 屏山县| 昌乐县| 奇台县| 随州市| 丰都县| 老河口市| 塔河县| 昂仁县| 牙克石市| 思南县| 贡嘎县| 油尖旺区| 大田县| 桂阳县| 兖州市| 乐陵市| 沿河| 兴仁县| 海南省| 方正县| 鄂伦春自治旗| 洪江市| 岗巴县| 曲水县| 赫章县| 安岳县| 佛坪县| 云浮市|