[ Team LiB ] Previous Section Next Section

Deleting Records

Before you can delete records, you must select them. The following sections therefore cover the process of selecting records and then the process of deleting records.

Selecting One or More Records

To select one record, you simply click the gray record selector button to the left of the record within the datasheet.

To select multiple records, you click and drag within the record selector area. Access selects the contiguous range of records in the area over which you click and drag. As an alternative, you can click the gray selector button for the first record you want to select, hold down the Shift key, and then click the gray selector button of the last record that you want to select. When you do this, Access selects the entire range of records between them. Figure 2.3 shows the Customers table with three records selected.

Figure 2.3. The Customers table with three records selected.

graphics/02fig03.jpg

If you want to select a single record when the cursor is within the record, you can simply select Edit | Select Record.

Deleting Records

When you know how to select records, deleting them is quite simple. You just follow these steps:

  1. Select the record(s) you want to delete.

  2. Press the Delete key. The dialog box in Figure 2.4 appears, asking if you're sure you want to delete the record(s).

    Figure 2.4. Access asks if you want to delete the selected record.

    graphics/02fig04.jpg

  3. Click the Yes button. Access deletes the records.

The process of deleting a record is not so simple if you have established referential integrity between the tables in a database and the row that you are attempting to delete has child rows. Hour 9, "Creating Relationships," covers relationships and referential integrity. For now, you can think about the fact that customers generally have orders associated with them, and those orders have order detail records associated with them. The relationship between the Customers table and the Orders table prohibits the user from deleting customers who have orders. Here's how you delete a customer who has orders:

  1. Select the record(s) you want to delete.

  2. Press the Delete key. The dialog box in Figure 2.5 appears, telling you that the records cannot be deleted because the table includes related records.

    Figure 2.5. Access notifying you that you cannot delete the selected records.

    graphics/02fig05.jpg

  3. Click OK to close the dialog box.

Access provides a referential integrity option with which you can cascade a deletion down to the child table (a table related to a parent table, such as orders related to customers). This means, for example, that if you attempt to delete an order, Access deletes the associated order detail records. If you establish referential integrity with the cascade delete option, the deletion process works like this:

  1. Select the record(s) you want to delete.

  2. Press the Delete key. The dialog box in Figure 2.6 appears, asking if you're sure you want to delete the records.

    Figure 2.6. Access asking if you want to delete the parent row and the associated child records.

    graphics/02fig06.jpg

  3. Click Yes to complete the deletion process.

graphics/book_icon.gif

After you have selected records, they appear in black and you can copy them, delete them, or modify them as a group. Remember that deleting records is a permanent process. You cannot undo record deletion.


    [ Team LiB ] Previous Section Next Section