目录

SQL INSERT INTO SELECT 关键字


INSERT INTO SELECT

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

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

示例

INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers;

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

示例

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
SELECT SupplierName, ContactName, Address, City, PostalCode, Country FROM Suppliers;

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

示例

INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers
WHERE Country='Germany';