Q:

Delete from multiple tables at once in azure

I am trying this SQL statement to delete from two tables at once but i find that it is only deleting from one table and giving me an error

The DELETE statement conflicted with the REFERENCE constraint "FK__cc_custom__custo__02084FDA". The conflict occurred in database "CurtainClub", table "dbo.cc_customer_address", column 'customer_number'.`

My sql statement is as follows:
BEGIN
SELECT * from cc_customer 
inner join cc_customer_address on customer_id=customer_number

delete from cc_customer where customer_id=3
delete from cc_customer_address where customer_number=3
END

Also please note that customer_number is the foreign key of customer_id

A:

You should swap DELETE statements:
BEGIN
  SELECT * 
  from cc_customer 
  inner join cc_customer_address on customer_id=customer_number;

  delete from cc_customer_address where customer_number=3;  -- first child
  delete from cc_customer where customer_id=3;              -- then parent
END

