Integrate check for connections into check for DB existance to avoid error on new creations of EHEC_DB

This commit is contained in:
Ivan Hörler 2018-07-29 11:05:07 +02:00
parent 971348764e
commit f7be1ac531
1 changed files with 4 additions and 10 deletions

View File

@ -11,20 +11,14 @@
-- 180629 Ivan, Add inserts for fixed lists
-- --------------------------------------------------
-- Set DB toSingle User so open connections do not block
-- --------------------------------------------------
PRINT 'Set Multiuser to Singleuser so all open connections are cut...';
use master
ALTER DATABASE EHEC_DB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
-- --------------------------------------------------
-- Auskommentieren für Löschung der Datenbank
IF db_id('EHEC_DB') is not null
BEGIN;
PRINT 'EHEC_DB already EXISTS, db will be deleted for a new creation.'
PRINT 'EHEC_DB already EXISTS, Set Multiuser to Singleuser so all open connections are cut...';
USE [master];
-- Set DB toSingle User so open connections do not block Destroy of DB
ALTER DATABASE EHEC_DB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
PRINT 'DB will be deleted for a new creation.'
DROP DATABASE EHEC_DB;
END;
ELSE