Sample Exam Questions

From the objective of OSS-DB Exam Silver
S3.1 SQL commands (INSERT statement)

Sample Question

3.51

Choose the two most appropriate descriptions for an INSERT statement of the form:

INSERT INTO table_name(col1, col2...) VALUES (val1, val2...)

  1. If the table specified with table_name does not exist, it is automatically created.

  2. The column list specified with col1, col2 ... does not have to match the order of the columns in the actual table.

  3. Any columns in the table that are not included in the column list col1, col2 ... will be filled with NULL.

  4. If the number of data items in the value list specified with val1, val2 ... is larger than the number of columns in the column list specified with col1, col2 ..., then an error occurs.

  5. If the number of data items in the value list specified with val1, val2 ... is less than the number of columns in the column list specified with col1, col2 ..., then NULL is assumed for those columns.

※This sample exam is different from those that appear in the actual OSS-DB Exam.
2024/05/02

Answer and Explanation

INSERT is an SQL statement that adds data to a table. Due to its name, the phrase "insert row" is often used; however, the concept of SQL's INSERT is closer to "append."

INSERT does not have the capability to create a new table; the table must be created beforehand using CREATE TABLE.

For columns not specified in the column list, data is created with the default value for that column (the value specified by DEFAULT in the column attribute, for example, in CREATE TABLE). Please note that columns that do not have a DEFAULT specified will be filled with NULL. While this often results in many NULL values, it is not always the case.

The column list specified with col1, col2 ... can be ordered independently from the column list specified in CREATE TABLE. However, the value list specified with val1, val2 ... must correspond to each member of the column list specified with col1, col2 ..., and the number of values must match the number of columns specified. Having too many or too few values will result in an error.

Alternatively, the INSERT statement can be written as INSERT INTO table_name VALUES (val1, val2 ...), omitting the column list. In this case, the behavior is as if a column list, listing all the columns of the table in their defined order, was specified. However, the number of data items in the value list can be fewer than the number of columns, and any missing columns are assumed to have DEFAULT specified (Different types of RDBMS have different implementations, and some may return an error if there are missing values). Be careful not to confuse this case.

So the correct answers are B and D.