title: Delete rows from two tables
body: <p>I have two tables. Those tables have two relation between them. </p>
  
  <pre><code>Table 1
     * ID_XPTO (PK)
     * Detail
  
  Table 2
     * ID_XPTO (FK) (PK)
     * ID_XPTO2 (FK) (PK)
  </code></pre>
  
  <p>Those two relations exists.</p>
  
  <pre><code>Table 1 -&lt; Table2 
  Table 1 -&lt; Table2
  </code></pre>
  
  <p>My question is that I need to delete some row in table 1. I'm currently doing,</p>
  
  <pre><code>declare @table Table (xptoTable2 int)
  insert into @table
          select ID_XPTO2
          from Table2 
          where ID_XPTO = @ID_XPTO
  
  delete from Table2
  where ID_XPTO = @ID_XPTO
  
  delete from Table
  where ID_XPTO in (select xptoTable2from @table)
  </code></pre>
  
  <p>I know that I could use ON DELETE SET NULL on table2. On that way I could then search for all rows with null value on ID_XPTO2 and delete them, but DBA does not wants to use it.</p>
  
  <p>Is there some better solution to do this process?</p>