Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
carljohan_larsson
Starting Member
1 Post |
Posted - 2010-09-27 : 02:33:43
|
Hi,I have a script that creates a database and lots of tables. I would like to abort the entire script if the database exists.The problem I have is that the script continues to run whatever I tried to do.Here is the beginning of the script:USE Database1IF EXISTS (SELECT * FROM [dbo].[Table1])BEGINPRINT 'Database1 exists'RETURNENDELSE BEGINCREATE DATABASE Database1USE Database1bla bla blaI would like thre script to completely stop at line 5 (Return). |
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-09-27 : 03:11:31
|
DECLARE @DBName AS VARCHAR(100)SET @DBName = 'testDB'IF NOT EXISTS( SELECT 1 FROM sys.databases WHERE Name = @DBName )BEGIN <Your Script> .... ....ENDELSEBEGIN PRINT 'Database Exists'ENDVaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
|
|