I am curious how the database know which table has to inserted first if it is a single query, in order to maintain the constraint rules.
What you need to do is pack your queries in a
Transaction
. it allows you to roll back if any query fails.
Stored procedure is a good way to avoid trips
Have a look at here how to roll back in a stored procedure, in case of errors.
http://www.eggheadcafe.com/tutorials/aspnet/6a8ef7d5-840e-4629-b53a-1a40e7db601f/using-try--catch-to-roll.aspx[
^]