W3. SQL Select Into Flashcards

1
Q

Q: What does the SQL SELECT INTO statement do?

A

A: It copies data from one table into a new table.

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

Q: Write the syntax for copying all columns into a new table using SELECT INTO.

A

SELECT *
INTO newtable
FROM oldtable
WHERE condition;

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

Q: How do you copy only specific columns into a new table using SELECT INTO?

A

SELECT column1, column2, …
INTO newtable
FROM oldtable
WHERE condition;

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

Q: Can you use AS to rename columns when copying with SELECT INTO?

A

A: Yes, AS can be used to create new column names in the copied table.

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

Q: Write a query to create a backup copy of the Customers table.

A

SELECT * INTO CustomersBackup2017
FROM Customers;

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

Q: How do you use IN with SELECT INTO to copy data to another database?

A

A: Use IN ‘externaldb’, e.g.,

SELECT * INTO CustomersBackup2017 IN ‘Backup.mdb’
FROM Customers;

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

Q: Write a query to copy only CustomerName and ContactName into a new table.

A

SELECT CustomerName, ContactName
INTO CustomersBackup2017
FROM Customers;

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 customers into a new table.

A

SELECT * INTO CustomersGermany
FROM Customers
WHERE Country = ‘Germany’;

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

Q: Can SELECT INTO be used with JOIN to copy data from multiple tables?

A

A: Yes, JOIN can be used to select data from multiple tables into a new table.

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

Q: Write a query to copy data from Customers and Orders into a new table.

A

SELECT Customers.CustomerName, Orders.OrderID
INTO CustomersOrderBackup2017
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;

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

Q: How can you create a new, empty table with the schema of another table using SELECT INTO?

A

A: Use a WHERE clause that returns no data, e.g., WHERE 1 = 0.

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

Q: Write a query to create a new, empty table with the schema of an old table.

A

SELECT * INTO newtable
FROM oldtable
WHERE 1 = 0;

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