You can copy rows from one table to another or within a table using an Insert query. For example, in a titles
table, you can use an Insert Query to copy information about all the titles for one publisher to a second table that you can make available to that publisher. An Insert query is similar to a Make Table query, but copies rows into an existing table.
Tip You can also copy rows from one table to another using cut and paste. For details, see Adding New Rows in the Results Pane.
When you create an Insert query, you specify:
For example, the following query copies title information from the titles
table to an archive table called archivetitles
. The query copies the contents of four columns for all titles belonging to a particular publisher:
INSERT INTO archivetitles
(title_id, title, type, pub_id)
SELECT title_id, title, type, pub_id
FROM titles
WHERE (pub_id = '0766')
Note To insert values into a new row, use an Insert Values query.
For general information about using queries to update tables, see Modifying Data Using Queries.
You can copy the contents of selected columns or of all columns in a row. In either case, the data you are copying must be compatible with the columns in the rows you are copying to. For example, if you copy the contents of a column such as price
, the column in the row you are copying to must accept numeric data with decimal places. If you are copying an entire row, the destination table must have compatible columns in the same physical position as the source table.
When you create an Insert query, the Grid pane changes to reflect options available for copying data. Because you do not display data in an Insert query, the Output column is removed. An Append column is added to allow you to specify the columns into which data should be copied.
Caution You cannot undo the action of executing an Insert query. As a precaution, back up your data before executing the query.
To create an Insert query
Note The Query Designer cannot determine in advance which tables and views you can update. Therefore, the Table Name list in the Insert Into Table dialog box shows all available tables and views in the data connection you are querying, even those that you might not be able to copy rows to.
The data columns from the source table appear in an input window in the Diagram pane.
The Query Designer adds the columns you choose to the Column column of the Grid pane.
If you do not specify a search condition, all rows from the source table will be copied to the destination table.
Note When you add a column to search to the Grid pane, the Query Designer also adds it to the list of columns to copy. If you want to use a column for searching but not copy it, clear the check box next to the column name in the input source window ( ).
When you execute an Insert query, no results are reported in the Results pane. Instead, a message appears indicating how many rows were copied.