Actions Queries Understanding Action Queries q Action queries

  • Slides: 19
Download presentation
Actions Queries

Actions Queries

Understanding Action Queries q Action queries are a way to make corrections to database.

Understanding Action Queries q Action queries are a way to make corrections to database. They can make an enormous mess of database if used incorrectly. q Action queries differ from select queries: − A select query shows you data that meet your criteria. − An action query looks for the data that meets your criteria, and then does something with it, such as making changes to the data or moving records to a new table.

Testing Action Queries (Carefully) q Most importantly, before you use an action query, make

Testing Action Queries (Carefully) q Most importantly, before you use an action query, make a database backup! because it may not always generate the result you expect (mong đợi). q To make a backup, you can copy your. accdb database file or File➝Save & Publish to enter Backstage view, look in the Advanced section of the Save Database As list Back Up Database.

The Action Query Family q An update query changes the values in one or

The Action Query Family q An update query changes the values in one or more records. q An append query selects one or more records, and then adds them to an existing table. q A make-table query selects one or more records, and then creates a new table for them. q A delete query deletes one or more records.

Update Queries q An update query searches for some records and then modifies them.

Update Queries q An update query searches for some records and then modifies them. q Using the update query when you work on lots of data or when you want to update multiple fields. q Update query makes to change multiple records at same time.

Update Queries q To Create a Update Query: − Select Create tab Queries Query

Update Queries q To Create a Update Query: − Select Create tab Queries Query Design. − Add each table you want to include in query by selecting it and then clicking Add. − Change query to an update query by choosing Query Tools Design Query Type Update. −

Update Queries − Add the field you want to change. − In the Update

Update Queries − Add the field you want to change. − In the Update To box, supply the new value that your query will apply to each field.

Update Queries − Add any other fields that you want to inspect to confirm

Update Queries − Add any other fields that you want to inspect to confirm that you’re selecting the correct records. − Right-click the query’s tab title, and choose Datasheet View to see the rows that query affects. − Now switch back to Design view, choose Query Tools Design Results Run to run update query and have Access apply your changes.

Update Queries q Access warns you about the change it’s about to make. Click

Update Queries q Access warns you about the change it’s about to make. Click Yes to make the change. q If you want to save your query, then press Ctrl+S You’ll need to supply a name for your query.

Append Queries q An append query selects records from a table and then inserts

Append Queries q An append query selects records from a table and then inserts them into the end another table. q You may want to use an append query to transfer records from one database to another. This technique is handy if you have duplicate tables in different databases. q To transfer the records, you need to make sure the two tables line up. (Page 255)

Append Queries q Create a new query by choosing Create Queries Query Design. q

Append Queries q Create a new query by choosing Create Queries Query Design. q Using the Show Table dialog box, add the source table that has the records you want to copy. q Query Tools Design ➝ Query Type ➝Append.

Append Queries − Another Database: transfer the records to

Append Queries − Another Database: transfer the records to

Append Queries − If you’re creating an append query, then fill in the names

Append Queries − If you’re creating an append query, then fill in the names of the destination fields in the Append To boxes. − If want to copy only some of the records in the source table, then set the filter conditions you need. − Choose Datasheet View to see the rows that your query affects.

Append Queries − Switch back to Design view, and then choose Query Tools Design

Append Queries − Switch back to Design view, and then choose Query Tools Design Results Run to transfer your records. − Press Ctrl+S to save query.

Make-Table Query q The make-table query creates the destination table, and then copies the

Make-Table Query q The make-table query creates the destination table, and then copies the records to it. − Open the source database. − Choosing Create ➝ Queries ➝ Query Design. − Add the source table that has the records you want to copy. − Select Query Tools ➝ Design ➝ Query Type ➝ Make Table.

Make-Table Query − Another database: transfer the records to another Database, click Browse to

Make-Table Query − Another database: transfer the records to another Database, click Browse to select database file OK. − Table Name: enter the name of the table which you want to transfer the records.

Make-Table Query − Add the field you want to copy from the − −

Make-Table Query − Add the field you want to copy from the − − source table. To copy only some of the records in the source table, then set the filter conditions. Choose Datasheet View to see the rows that your query affects. Switch back to Design view Results ➝ Run to transfer the records. Press Ctrl + S to save query.

Delete Queries q Delete queries are the simplest and most dangerous of the action

Delete Queries q Delete queries are the simplest and most dangerous of the action queries. q Delete query erases records from the database. q To create a delete query: − Select Create tab ➝ Queries ➝ Query Design. − Add the table that has the records you want to delete. − Select Query Tools Design ➝ Query Type ➝ Delete.

Delete Queries − Add the fields you want to use for filtering, and then

Delete Queries − Add the fields you want to use for filtering, and then set filter conditions. − Add the fields that you want to inspect to confirm you’re getting the correct records in the datasheet view. − Choose Datasheet View to see the rows that’ll be affected by query. − Switch back to Design view, choose Query Tools Design Results Run to remove the records.