enhance SQL DB Creation file with Single connection to avoid errors in new creation.

This commit is contained in:
Ivan Hörler 2018-07-14 10:58:42 +02:00
parent 7ebabf41b2
commit a9defbad51
1 changed files with 16 additions and 5 deletions

View File

@ -11,16 +11,25 @@
-- 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 existiert bereits, sie wird nun geloescht und neu Gebaut'
PRINT 'EHEC_DB already EXISTS, db will be deleted for a new creation.'
USE [master];
DROP DATABASE EHEC_DB;
END;
ELSE
BEGIN;
PRINT 'EHEC_DB existiert noch nicht, die Datenbank wird nun neu Gebaut';
PRINT 'EHEC_DB does NOT EXISTS, the db will be created now...';
END;
GO
@ -273,9 +282,11 @@ VALUES
('EHEC-D'),
('EHEC-E')
GO
-- --------------------------------------------------
PRINT 'Erfolgreich!';
PRINT 'Set Singleuser mode back to Multiuser mode.';
-- set DB back to Multiuser so multiconnections are alowed again.
ALTER DATABASE EHEC_DB SET MULTI_USER
-- --------------------------------------------------
PRINT 'Successfull created your DB!';
-- Script has ended
-- --------------------------------------------------