i have the following script and i saved as SQL script file. I am executing this script every time in my client production db during migration. All my script files i have check condition in the top. If the condition is successful it should not execute this file and it should break the execution and it need to say 'Invalid database'.
But when i execute this script the if condition in the top is executing with 'Invalid database' message. But the script does not break and it is executing all the below insert table commands. How to stop this ?
If it is invalid database below lines should not execute. How to prevent this ?
IF NOT EXISTS(SELECT * FROM configTable where configValue like 'SVS1' ))
raiserror('Invalid database', 15, 10)
insert into table a (name,age) values ('aaa',20)
insert into table a (name,age) values ('aaaa',21)
insert into table a (name,age) values ('bb',21)