W3. SQL Insert Into Select Flashcards

1
Q

Q: What does the SQL INSERT INTO SELECT statement do?

A

A: It copies data from one table and inserts it into another table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: Does INSERT INTO SELECT affect existing records in the target table?

A

A: No, it only adds new records and leaves existing records unaffected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: What must be true about the data types when using INSERT INTO SELECT?

A

A: The data types in the source and target tables must match.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: Write the syntax for copying all columns from one table to another.

A

INSERT INTO table2
SELECT * FROM table1
WHERE condition;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: Write the syntax for copying specific columns from one table to another.

A

INSERT INTO table2 (column1, column2, …)
SELECT column1, column2, …
FROM table1
WHERE condition;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: Write a query to copy SupplierName, City, and Country from Suppliers to Customers.

A

INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country
FROM Suppliers;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: Write a query to copy all columns from Suppliers to Customers.

A

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
SELECT SupplierName, ContactName, Address, City, PostalCode, Country
FROM Suppliers;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: Write a query to copy only German suppliers into Customers.

A

INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country
FROM Suppliers
WHERE Country = ‘Germany’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly