SQL Select Into语句
SELECT INTO 语句
The SELECT INTO statement is most often used to create backup copies of tables or for archiving records.
SELECT INTO语句常用来给数据表建立备份或是历史档案。
Syntax
语法
SELECT column_name(s) INTO newtable [IN externaldatabase] FROM source
|
Make a Backup Copy
制作一个备份
The following example makes a backup copy of the "Persons" table:
下面的例子中会为"Persons"表制作一个备份
SELECT * INTO Persons_backupFROM Persons
|
The IN clause can be used to copy tables into another database:
IN子句可以用来将多个数据表拷贝到另一个数据库上:
SELECT Persons.* INTO Persons IN 'Backup.mdb'FROM Persons
|
If you only want to copy a few fields, you can do so by listing them after the SELECT statement:
如果你仅仅想拷贝其中的一部分,可以在SELECT后面列举出它们:
SELECT LastName,FirstName INTO Persons_backupFROM Persons
|
You can also add a WHERE clause. The following example creates a "Persons_backup" table with two columns (FirstName and LastName) by extracting the persons who lives in "Sandnes" from the "Persons" table:
你还可以加上WHERE子句。在下面的举例中会建立一个"Persons_backup"表,里面包含了在"Persons"表中住在"Sandnes"的个人姓(LastName)与名(FirstName)信息。
SELECT LastName,Firstname INTO Persons_backupFROM PersonsWHERE City='Sandnes'
|
Selecting data from more than one table is also possible. The following example creates a new table "Empl_Ord_backup" that contains data from the two tables Employees and Orders:
选择多个表进行备份也是可以的。下面的举例就建立了一个新的表"Empl_Ord_backup"里面的数据就有Employees和Orders这两张表的内容:
SELECT Employees.Name,Orders.ProductINTO Empl_Ord_backupFROM EmployeesINNER JOIN OrdersON Employees.Employee_ID=Orders.Employee_ID
|