This is what I am trying to accomplish:
Check if database is read-only in first step of SQL Server Agent job. If this is the case - exit the job.
So I figured I will use Advanced Properties for Job Step and select "Quit the job reporting success" for "On failure cation:"
But how does one fail T-SQL script without using RAISERROR()? Reason I don't want to use RAISERROR() is because one needs to be a member of sysadmin server role to use it.
I found rather ugly approach that works - selecting something from the table that doesn't exist, script looks like this:
declare @DBIsRO int;
SET @DBIsRO= (SELECT is_read_only
FROM sys.databases
WHERE name = 'test')
IF @DBIsRO=1
select * from dd -- table dd doesn't exist in current database
However, this just seems like a kludge and I am looking for a 'proper' approach.