Results 1 to 2 of 2
  1. #1
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82

    How would I delete rows from three tables in one query?

    I have 3 tables, Compositions, Discs, and DiscContents (which connects a row in Compositions to a row in Discs).

    How would I write a Delete Query that would do these three deletes in one fell swoop (I'll hardcode ID numbers for this example)?

    DELETE FROM Compositions WHERE CompositionID = 424

    DELETE FROM Discs WHERE DiscID = 320



    DELETE FROM DiscContents WHERE composition_id = 424 and disc_id = 320

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,423
    you don't, you have to use three separate queries

    however if your relationships are set up to maintain referential integrity and you have selected Cascade delete related records then deleting the primary table record (on the one side of the relationship) will also delete all the related records in the child table(s)

    otherwise you will need to run some code to run each query in sequence - and bearing in mind if you have set referential integrity, you will need to delete the child records first. Code would be something like

    currentdb.execute "DELETE FROM Compositions WHERE CompositionID = 424"
    currentdb.execute "DELETE FROM Discs WHERE DiscID = 320"
    currentdb.execute "DELETE FROM DiscContents WHERE composition_id = 424 and disc_id = 320"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 12-13-2016, 09:48 AM
  2. Delete Query for Tables with Relationships
    By mgilbert86 in forum Queries
    Replies: 1
    Last Post: 10-19-2016, 10:06 AM
  3. Query to delete across tables
    By Gauchey in forum Queries
    Replies: 7
    Last Post: 07-17-2015, 12:49 PM
  4. Delete Rows with Same ID and Due Date??
    By taimysho0 in forum Programming
    Replies: 2
    Last Post: 03-01-2012, 12:14 PM
  5. Replies: 3
    Last Post: 07-16-2010, 12:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums