SQL INSERT INTO SELECT 关键字
INSERT INTO SELECT
INSERT INTO SELECT
命令从一个表中复制数据并将其插入到另一个表中。
以下 SQL 将"供应商"复制到"客户"(未填充数据的列将包含 NULL):
实例
INSERT INTO Customers (CustomerName,
City, Country)
SELECT SupplierName, City, Country FROM Suppliers;
亲自试一试 »
以下 SQL 将"供应商"复制到"客户"中(填充所有列):
实例
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';
亲自试一试 »