W3. SQL Insert Into Select Flashcards
Q: What does the SQL INSERT INTO SELECT statement do?
A: It copies data from one table and inserts it into another table.
Q: Does INSERT INTO SELECT affect existing records in the target table?
A: No, it only adds new records and leaves existing records unaffected.
Q: What must be true about the data types when using INSERT INTO SELECT?
A: The data types in the source and target tables must match.
Q: Write the syntax for copying all columns from one table to another.
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
Q: Write the syntax for copying specific columns from one table to another.
INSERT INTO table2 (column1, column2, …)
SELECT column1, column2, …
FROM table1
WHERE condition;
Q: Write a query to copy SupplierName, City, and Country from Suppliers to Customers.
INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country
FROM Suppliers;
Q: Write a query to copy all columns from Suppliers to Customers.
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
SELECT SupplierName, ContactName, Address, City, PostalCode, Country
FROM Suppliers;
Q: Write a query to copy only German suppliers into Customers.
INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country
FROM Suppliers
WHERE Country = ‘Germany’;