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';