title: How to fail T-SQL script without using RAISERROR()?
body: <p>This is what I am trying to accomplish:</p>
  
  <p>Check if database is read-only in first step of SQL Server Agent job. If this is the case - exit the job.</p>
  
  <p>So I figured I will use Advanced Properties for Job Step and select "Quit the job reporting success" for "On failure cation:"</p>
  
  <p>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.</p>
  
  <p>I found rather ugly approach that works - selecting something from the table that doesn't exist, script looks like this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>However, this just seems like a kludge and I am looking for a 'proper' approach.</p>