Select INTO and insert INTO

Source: Internet
Author: User

SELECT ... INTO statement

Create a tab search.
Grammar

SELECT field1[, field2[, ...] into a new table [in external database]
From source

SELECT ... Into statements can be divided into the following sections: Partial description
Field1, field2 the name of the field that you want to copy to the new table.
NewTable the name of the table you want to create. It should follow the standard Nomenclature convention. If the name of the newtable is the same as the name of an existing table, a catch error can occur.
Externaldatabase the path into the external database. For a description of the path, see the IN clause.
The name of the existing table from which source selects records. It can be a single table or multiple tables or a query.
View:

Http://www.aspxuexi.com/sql/sql/2006-4-8/select_insert.htm

(Copy records and tables with Select)

Description

You can use a make-table query to archive records, generate copy backups of a table, or generate a copy of a table that is output to another database, or as a basis for reports that display data on a regular basis. For example, you can run the same make-table query once a month to generate a regional sales report.

Attention
Perhaps you want to define a primary key for the new table. When you create a new table, the fields in the new table inherit the data type and size of each field in the Query base table, but do not pass other fields or table properties.
Use the INSERT into statement without creating an append search to add data to the current table.
Before you run a make-table query, to know which records will be selected, you can first look at the results of a SELECT statement that uses the same selection criteria.

SELECT ... INTO statement sample

This example selects all records in the employee table and then copies them to a new table named Emp Backup.

Sub Selectintox ()


Dim DBS as Database

Dim QDF as QueryDef


' Modify this line on your computer to correctly point to the path to Northwind.

Set dbs = OpenDatabase ("Northwind.mdb")

' On shipping orders exceeding $ $,


"Select All records in the employee table,

' and copy it to a new table called Employee backup.

Dbs. Execute "SELECT employees.* into" _

& "[Emp Backup] from Employees;"

' Delete QueryDef because this is a demo.

Dbs. Execute "DROP TABLE [Emp Backup];"

Dbs. Close


End Sub

Insert data into another table in Access: (Blue ideal rustling rain)

We all know select INTO bar.
Like what:
=========================
SELECT INTO TableB
SELECT * FROM TableA
where Username= ' abc '
=============================
A new table TableB is created to insert the qualifying records in the TableA into the TableB.
This is done in an MDB file.

Now I want to insert the qualifying records in the A.mdb table TableA into the TableB of B.mdb,
Do you have any good ideas?
Haha, I began to think of the first to retrieve the TableA A.mdb, and then loop the recordset into B.mdb.
This requires opening two connection.

Later I found a trick (master don't say old ah ...) )
First you have to know the physical address of the B.mdb. This is represented by a todbfile variable (which can be obtained by Server.MapPath).
====================================
Sql= "INSERT into TableB in" "& Todbfile &" "SELECT * from TableA where username= ' abc '"
=======================================
Just establish a connection to the A.mdb. Executing this SQL statement is all OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.