SQL INSERT INTO SELECT 关键字
INSERT INTO SELECT
The 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';