目录

SQL SELECT INTO 关键字


SELECT INTO

这个SELECT INTO命令从一张表复制数据并将其插入到一张新表中。

以下 SQL 语句创建 Customer 的备份副本:

SELECT * INTO CustomersBackup2017
FROM Customers;

以下 SQL 语句使用 IN 子句将表复制到另一个数据库中的新表中:

SELECT * INTO CustomersBackup2017 IN 'Backup.mdb'
FROM Customers;

以下 SQL 语句仅将几列复制到新表中:

SELECT CustomerName, ContactName INTO CustomersBackup2017
FROM Customers;

以下 SQL 语句仅将德国客户复制到新表中:

SELECT * INTO CustomersGermany
FROM Customers
WHERE Country = 'Germany';

以下 SQL 语句将多个表中的数据复制到一个新表中:

SELECT Customers.CustomerName, Orders.OrderID
INTO CustomersOrderBackup2017
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;