Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 311175 - Last Review: January 31, 2007 - Revision: 5.4
Part 8 of "Keeping Your Information Accurate" in Access 2003 and Access 2002: "Deleting Information From a Table"
This article was previously published under Q311175
On This Page
SUMMARY
The information covered in this article is provided by:
Microsoft
Press
(http://mspress.microsoft.com/)
.
This article is part 8 of a series of eight
articles that explain how to keep your information in Access accurate. To view
the other articles in this series, please see the "Additional Resources"
section later in this article.
This information is an excerpt from
the
Microsoft Access Version 2002 Step by Step book, Chapter 6: "Keeping Your Information Accurate". Learn More
About
Microsoft
Access Version 2002 Step by Step
(http://www.microsoft.com/mspress/books/sampchap/5054.aspx)
.
MORE INFORMATION
Eventually, the time comes to clean house and discard some
records. You could do this by scrolling through the tables and deleting records
by hand, but if all the records to be deleted match some pattern, you can use a
delete query to quickly get rid of all of them.
IMPORTANT: Keep in mind several things when deleting records from a
database. The effects of a delete query can be more far-reaching than you
intend. If the table where you are deleting records has a relationship with
another table and the
Cascade Delete Related Records option
for that relationship is set, records in the second table will also be deleted.
Sometimes this is what you want, but sometimes it isn't. For example, you don't
want to delete the records of previous sales just because you're deleting
discontinued products. Be sure to back up your database before deleting any
records.
- Open the database you want to use.
- In the Database window, click Queries under Objects.
- Double-click Create query in Design view
to open both the query window and the Show Table dialog box.
- Double-click the table you want to use to add that table to
the list area of the query window, and then click Close to close the Show Table dialog box.
- Drag the asterisk (*) from the field list for the table to
the query design grid. Or, double-click the asterisk at the top of the list of
fields to include all the fields in the query.
TIP: Clicking the asterisk in the field list is a quick way to move
all the fields in the table to the query, without having each field appear in
its own column. However, then you can't set Sort, Show, and Criteria values for individual fields. To set these values, you have to
add the specific fields to the design grid, thereby adding them twice. To avoid
displaying the fields twice, clear the check mark in the Show row of the duplicate individual fields. - In query Design view, click the arrow next to Query Type on the toolbar, and then click Delete Query.
In the design grid, the Sort and Show rows have disappeared, and a Delete row has been added. In the first column, which contains the
reference to all fields in the table, the Delete row contains the word From, indicating that this is the table from which records will be
deleted. When you add individual fields to the remaining columns, the Delete row displays Where, indicating that this field can include deletion criteria.
- From appears in the Delete cell under this field.
- 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. - In the Criteria cell for the fields that you have dragged to the grid, type the
criteria.
- To preview the records that will be deleted, click View on the toolbar. To return to query Design view, click View on the toolbar again. Make any changes you want in Design
view.
TIP: Before actually deleting records, you might want to display the
Relationships window by clicking Relationships on the Tools menu. If the table you are deleting from has a relationship with
any table containing information that shouldn't be deleted, right-click the
relationship line, click Edit Relationship on the shortcut menu, and make sure that Enforce Referential Integrity is selected and Cascade Delete Related Records
is not selected. - Click Run on the toolbar to delete the records.
Access displays a
warning to remind you of the permanence of this action. - Click Yes to delete the records.
Access displays another warning
if it cannot delete any records due to key violations. For example, if you are
deleting discontinued products and a discontinued product has been ordered so
that it appears in a table for ordered products. - Click Yes to run the query. Access displays a warning to let you know that
you are about to delete records permanently. Click View to see any items that were not deleted.
- If you think you might want to run the same delete query in
the future, click the Save button and provide a name to save it. Then close the
query.
TIP: If you are concerned that someone might accidentally run a
delete query and destroy records you weren't ready to destroy, change the query
back to a select query before saving it. You can then open the select query in
Design view and change it to a delete query when you want to run it
again. - Close the query, and then close the database.
ADDITIONAL RESOURCES
REFERENCES
The information in this article is an excerpt from the
Microsoft Access Version 2002 Step by Step book, published by Microsoft Press.
Collapse this imageExpand this image
(http://www.microsoft.com/mspress/books/sampchap/5054.aspx)
Learn More About
Microsoft
Access Version 2002 Step by Step
(http://www.microsoft.com/mspress/books/sampchap/5054.aspx)
For more information
about this publication and other Microsoft Press titles, see
http://mspress.microsoft.com
(http://mspress.microsoft.com)
.
APPLIES TO
- Microsoft Office Access 2003
- Microsoft Access 2002 Standard Edition
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please