Considering standard SQL, what is true about inserting rows using the SQL INSERT statement?

Difficulty: Easy

Correct Answer: Rows can be inserted one at a time or in groups (using INSERT ... SELECT)

Explanation:


Introduction / Context:
SQL provides flexible ways to add data to tables. Knowing the variations helps with performance, ETL tasks, and application simplicity.



Given Data / Assumptions:

  • We are using standard INSERT syntax.
  • We may insert literal rows or copy results from another query.
  • NULL defaults and column lists can be used to omit some columns.


Concept / Approach:
INSERT supports two common modes: row-at-a-time with VALUES, and set-based with INSERT ... SELECT, which can insert many rows in one statement. The choice affects performance and transaction behavior. It is not limited to one row per statement, and it is perfectly valid to copy rows from other tables or views via SELECT.



Step-by-Step Solution:

Recognize INSERT VALUES for single or multiple rows (vendor-dependent syntax allows VALUES lists).Recognize INSERT ... SELECT to insert a set returned by a query (potentially thousands of rows).Conclude that both per-row and set-based inserts are supported.


Verification / Alternative check:
Examples: INSERT INTO t(col1,col2) SELECT a,b FROM src WHERE ...; or INSERT INTO t VALUES (1,'a'), (2,'b') in systems that allow multi-values.



Why Other Options Are Wrong:
Only modify / cannot copy: Confuses INSERT with UPDATE; copying via SELECT is standard.
Only one at a time: Not true for INSERT ... SELECT (and multi-VALUES in many RDBMS).
Requires values for every column: Column lists and defaults/NULLs allow partial inserts.



Common Pitfalls:
For large batch inserts, remember to manage constraints and indexes to maintain performance and integrity.



Final Answer:
Rows can be inserted one at a time or in groups (using INSERT ... SELECT)

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion