SQL INSERT INTO SELECT 关键字

INSERT INTO SELECT

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

以下 SQL 将 "Suppliers" 复制到 "Customers" 中(未填充数据的列将包含 NULL):

实例
  1. INSERT INTO Customers (CustomerName, City, Country)
  2. SELECT SupplierName, City, Country FROM Suppliers;

以下 SQL 将 "Suppliers" 复制到 "Customers" 中(填写所有列):

实例
  1. INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
  2. SELECT SupplierName, ContactName, Address, City, PostalCode, Country FROM Suppliers;

以下 SQL 仅将德国供应商复制到 "Customers" 中:

实例
  1. INSERT INTO Customers (CustomerName, City, Country)
  2. SELECT SupplierName, City, Country FROM Suppliers
  3. WHERE Country='Germany';

分类导航