title: IF statement for deleting in SQL Server
body: <p>I have two tables in my database called <strong>Phases</strong> and <strong>Releases</strong>. The first one contains a Foreign Key to the <code>Releases</code> on <code>Id</code> named <code>ReleaseId</code>. If I want to delete a <code>Release</code>, firstly I want to check whether there is any <code>Phase</code> in it (as in, there is any column in <code>Phases</code> containing the <code>Id</code> of a <code>Release</code>). If there is, I delete the <code>Phase</code>, and then the <code>Release</code>. Otherwise, I just delete the <code>Release</code>.</p>
  
  <p>Therefore, I put together the following query written in my SQL Server:</p>
  
  <pre><code>IF (SELECT * FROM Phases WHERE ReleaseId='2002') IS NOT NULL
  BEGIN
  DELETE FROM Phases WHERE ReleaseId='2002'
  DELETE FROM Releases WHERE Id='2002'
  END
  ELSE
  BEGIN
  DELETE FROM Releases WHERE Id='2002'
  END
  </code></pre>
  
  <p>But this gives me the following error:</p>
  
  <blockquote>
    <p>Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.</p>
  </blockquote>
  
  <p>I am pretty bad with SQL, hence I couldn't figure out a solution for this issue. What is going wrong?</p>