I have created a batch script that creates stored procedures, alters and creates tables, etc. For a security measure I want to build in a check at the beginning of the batch file to ensure that the batch will only be run against the correct database.
Here is what I have tried:
declare @deployToDB varchar(100),
@currentDB varchar(100)
select @deployToDB = 'someDB',
@currentDB = db_name()
if @currentDB <> @deployDB
begin
return
end
<rest of batch file here>
The problem is that even if the @currentDB and @deployDB vars are different and the return statement is reached, the rest of the batch is executed.
I can't wrap the rest of the batch in an else block because of GO commands that exist.
I need a way to end all execution when the DB name check fails.
Here is what I have tried:
declare @deployToDB varchar(100),
@currentDB varchar(100)
select @deployToDB = 'someDB',
@currentDB = db_name()
if @currentDB <> @deployDB
begin
return
end
<rest of batch file here>
The problem is that even if the @currentDB and @deployDB vars are different and the return statement is reached, the rest of the batch is executed.
I can't wrap the rest of the batch in an else block because of GO commands that exist.
I need a way to end all execution when the DB name check fails.