Create a delete query (MDB)

Microsoft Office Access 2003

  • Once you delete records using a delete query, you can't undo the operation. Therefore, you should preview the data that the query selected for deletion before you run the query. You can do this by clicking View Button image on the toolbar, and viewing the query in Datasheet view.
  • You should maintain backup copies of your data at all times. If you delete the wrong records, you can retrieve them from your backup copies.
  • In some cases, running a delete query might delete records in related tables, even if they're not included in the query. This can happen when your query contains only the table that's on the "one" side of a one-to-many relationship, and you've enabled cascading deletes for that relationship. When you delete records from the "one" table, you'll also delete records from the "many" table.
  • When a delete query contains more than one table, such as a query that deletes duplicate records from one of the tables, the query’s UniqueRecords property must be set to Yes.

Show Delete records by using a query that includes only the "one" table in a one-to-many relationship

  1. Create a new query that contains the "one" table from which you want to delete records.

    ShowHow?

    1. In the Database window, click Queries Button image under Objects, and then click New on the Database window toolbar.
    2. In the New Query dialog box, click Design View, and then click OK.
    3. In the Show Table dialog box, click the tab that lists the tables or queries whose data you want to work with.
    4. Double-click the name of each object you want to add to the query, and then click Close.
    5. Add fields to the Field row in the design grid, and if you want, specify criteria and a sort order.
    6. To view the query's results, click View Button image on the toolbar.
  2. In query Design view, click the arrow next to Query Type Button image on the toolbar, and then click Delete Query.
  3. Drag the asterisk (*) from the field list for the table to the query design grid.

    From appears in the Delete cell under this field, as shown in the illustration that follows.

  4. To specify criteria for deleting records, drag to the design grid the fields on which you want to set criteria.

    Where appears in the Delete cell under this field, as shown in the following illustration.

    Enter criteria for deleting records

  5. In the Criteria cell for the fields that you have dragged to the grid, type the criteria.
  6. To preview the records that will be deleted, click View Button image on the toolbar. To return to query Design view, click View Button image on the toolbar again. Make any changes you want in Design view.
  7. Click Run Button image on the toolbar to delete the records.

Show Delete records by using a query that includes both tables in a one-to-many relationship

  1. Create a new query that contains the tables from which you want to delete records.

    ShowHow?

    1. In the Database window, click Queries Button image under Objects, and then click New on the Database window toolbar.
    2. In the New Query dialog box, click Design View, and then click OK.
    3. In the Show Table dialog box, click the tab that lists the tables or queries whose data you want to work with.
    4. Double-click the name of each object you want to add to the query, and then click Close.
    5. Add fields to the Field row in the design grid, and if you want, specify criteria and a sort order.
    6. To view the query's results, click View Button image on the toolbar.
  2. In query Design view, click the arrow next to Query Type Button image on the toolbar, and then click Delete Query.
  3. From the table with related records (on the "many" side of the one-to-many relationship), drag the asterisk (*) from the field list to the query design grid.

    From appears in the Delete cell under this field, as shown in the illustration that follows.

  4. To specify criteria for deleting records, drag the fields on which you want to set criteria from the primary table (on the "one" side of the one-to-many relationship) to the design grid.

    Where appears in the Delete cell under this field, as shown in the following illustration.

    Enter criteria for deleting records from both sides of a one-to-many relationship

  5. In the Criteria cell for the fields that you have dragged to the grid, type the criteria.
  6. To preview the records that will be deleted, click View Button image on the toolbar. To return to query Design view, click View Button image on the toolbar again. Make any changes you want in Design view.
  7. Click Run Button image on the toolbar to delete the records from the table on the "many" side.
  8. Select the field list for each table on the "many" side and press DELETE to remove it from the query.
  9. With just the primary table remaining in the query and the field on which you want to set criteria in the design grid, click Run Button image again.

    Microsoft Access deletes the specified records from the "one" table.

Show Delete records from a single table or multiple tables that have a one-to-one relationship

  1. Create a new query that contains the tables from which you want to delete records.

    ShowHow?

    1. In the Database window, click Queries Button image under Objects, and then click New on the Database window toolbar.
    2. In the New Query dialog box, click Design View, and then click OK.
    3. In the Show Table dialog box, click the tab that lists the tables or queries whose data you want to work with.
    4. Double-click the name of each object you want to add to the query, and then click Close.
    5. Add fields to the Field row in the design grid, and if you want, specify criteria and a sort order.
    6. To view the query's results, click View Button image on the toolbar.
  2. In query Design view, click the arrow next to Query Type Button image on the toolbar, and then click Delete Query.
  3. For the tables you want to delete records from, drag the asterisk (*) from the field list to the query design grid.

    From appears in the Delete cell under these fields, as shown in the illustration that follows.

  4. To specify criteria for deleting records, drag to the design grid the fields on which you want to set criteria.

    Where appears in the Delete cell under these fields, as shown in the following illustration.

    Enter criteria for deleting records

  5. In the Criteria cell for the fields that you have dragged to the grid, type the criteria.
  6. To preview the records that will be deleted, click View Button image on the toolbar. To return to query Design view, click View Button image on the toolbar again. Make any changes you want in Design view.
  7. Click Run Button image on the toolbar to delete the records.