title: SQL DELETE (Cascading DELETE vs. TRIGGERS vs. "Manual"-DELETE)
body: <p>I'm currently working with SQL Server Management Studio 2005 and I'm facing a bit of a problem, but first an extract (the important one) of my DB-schema:</p>
  
  <p><a href="http://www.imghack.se/64885" rel="nofollow">imghack link to the image</a></p>
  
  <p>I want to delete from the <code>test</code> table and everything it is connected to (is composed of).</p>
  
  <p>The problem is, I can't alter the DB anymore (and really wouldn't want to, cause the program using it got too big already).</p>
  
  <p>When I try to delete an entry in the <code>test</code> table and cascading DELETE is turned on for the corresponding foreign key relation the DBMS won't let me do the delete, because it detected some kind of loop (probably caused by the <code>contr_tray</code> table).</p>
  
  <p>When trying to delete an entry manually through my program (using a <code>SqlCommandBuilder</code> or <code>cmd.ExecuteNonQuery())</code> I get this error: </p>
  
  <blockquote>
    <p>The DELETE statement conflicted with the REFERENCE constraint ...</p>
  </blockquote>
  
  <p>The same happens if I use triggers, to "cascade" the deletion process downwards.</p>
  
  <p>Can anyone help me here? Thank you!</p>
  
  <p>P.S.: I also tried to create a joined table where all columns belonging to the <code>subset</code> table would simply be NULL where the <code>contr_tray</code> table had been joined to the replicate table and let the <code>SqlCommandBuilder</code> handle this, but my SQL skills don't seem up to par (i.e. i didn't get the SQL syntax right)[then I could also get the distinct values for all the IDs I would need ...]</p>
  
  <p>Any help would be appreciated and again thanks in advance.</p>