轻松上手,快乐学习!

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';
运行实例»