SQL SELECT INTO 关键字

SELECT INTO

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

以下 SQL 语句创建客户表的备份副本:

  1. SELECT * INTO CustomersBackup2017
  2. FROM Customers;

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

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

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

  1. SELECT CustomerName, ContactName INTO CustomersBackup2017
  2. FROM Customers;

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

  1. SELECT * INTO CustomersGermany
  2. FROM Customers
  3. WHERE Country = 'Germany';

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

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

分类导航