title: Transactions in SQL Server with Delete statement
body: <p>This is my task: write a script that includes two SQL statements coded as a transaction to delete the row with a customer ID of 8 from the <code>Customers</code> table. To do this, you must first delete all addresses for that customer from the <code>Addresses</code> table.</p>
  <p>If these statements execute successfully, commit the changes. Otherwise, roll back the changes.</p>
  <p>My problem is that I am getting an error that looks like this:</p>
  <blockquote>
  <p>Msg 547, Level 16, State 0, Line 9<br />
  The DELETE statement conflicted with the REFERENCE constraint &quot;FK__Orders__Customer__35BCFE0A&quot;. The conflict occurred in database &quot;MyGuitarShop&quot;, table &quot;dbo.Orders&quot;, column 'CustomerID'.</p>
  </blockquote>
  <p>My code:</p>
  <pre><code>BEGIN TRAN;
  
  DELETE FROM Addresses
  WHERE CustomerID = 8;
  
  DELETE FROM Customers
  WHERE CustomerID = 8;
  
  IF @@ROWCOUNT &gt; 1
  BEGIN
      ROLLBACK TRAN
      PRINT 'did not delete'
  END
  ELSE
  BEGIN
      COMMIT TRAN;
  END
  </code></pre>
  <p>Thank you!</p>