Master-Details Form application: inserting data in the database

How can I make it possible the master-details to be insert in the database at the same time And if the insertion of master or details fails both to not be inserted in the database?