SQL 语句 SELECT INTO 将数据从一张表复制到一张新表。
我们将所有列复制到一个新表中:
SELECT *
INTO newtable [IN externaldb]
FROM oldtable
WHERE condition
让我们仅将一些列复制到新表中:
SELECT column1, column2, column3, ...
INTO newtable [IN externaldb]
FROM oldtable
WHERE condition
将使用旧表中定义的列名称和数据类型创建一个新表。您可以使用 AS 表达式创建新的列名称。
以下 SQL 语句备份客户端:
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
SELECT * INTO newtable
FROM oldtable
WHERE 1 = 0