What does the INSERT INTO SELECT statement do?
A
Creates a new table and inserts data B
Copies data from one table into an existing table C
Deletes data from a table D
Updates rows in a table
Analysis & Theory
INSERT INTO SELECT copies rows into an *existing* table.
Which of the following is the correct syntax?
A
INSERT INTO NewTable SELECT * FROM OldTable; B
SELECT * INTO NewTable FROM OldTable; C
UPDATE NewTable SET SELECT * FROM OldTable; D
INSERT SELECT INTO NewTable FROM OldTable;
Analysis & Theory
Syntax: INSERT INTO TargetTable SELECT ... FROM SourceTable;
What happens if the column counts do not match in INSERT INTO SELECT?
A
Rows are skipped B
The statement succeeds C
An error occurs D
Extra columns are ignored
Analysis & Theory
Column counts and data types must match, or an error will occur.
True or False: You can use WHERE with INSERT INTO SELECT to filter rows.
A
True B
False
Analysis & Theory
WHERE filters which rows are inserted.
How would you copy only the 'Name' and 'Age' columns?
A
INSERT INTO TargetTable SELECT Name, Age FROM SourceTable; B
INSERT SELECT Name, Age INTO TargetTable FROM SourceTable; C
SELECT INTO TargetTable Name, Age FROM SourceTable; D
INSERT TargetTable SELECT Name, Age FROM SourceTable;
Analysis & Theory
List columns explicitly in SELECT.
Fill in the blank:
INSERT INTO EmployeesArchive (Name, Age)
______ Employees WHERE Active = 0;
A
INSERT Employees B
SELECT Name, Age FROM C
COPY FROM D
VALUES (Name, Age)
Analysis & Theory
Correct syntax: INSERT INTO ... SELECT ... FROM ...
Which clause would you use to avoid copying duplicate rows?
A
WHERE DISTINCT B
DISTINCT C
GROUP BY D
HAVING
Analysis & Theory
DISTINCT in SELECT removes duplicates.
What must exist before using INSERT INTO SELECT?
A
Target table must already exist B
Source table must be empty C
Target table must be empty D
Both tables must have identical names
Analysis & Theory
Unlike SELECT INTO, INSERT INTO SELECT requires the target table to exist.
Which query copies all data from Customers into CustomersBackup?
A
INSERT INTO CustomersBackup SELECT * FROM Customers; B
SELECT * INTO CustomersBackup FROM Customers; C
COPY Customers INTO CustomersBackup; D
INSERT SELECT * INTO CustomersBackup FROM Customers;
Analysis & Theory
INSERT INTO ... SELECT ... is the correct syntax for existing tables.
True or False: INSERT INTO SELECT can be combined with JOINs to insert data from multiple tables.
A
True B
False
Analysis & Theory
JOINs are allowed in the SELECT part of the statement.