Sample Exam Questions

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

Sample Question

3.11

When is an index automatically created when CREATE TABLE is executed? Choose all that apply.

  1. When a table has a FOREIGN KEY constraint
  2. When a NOT NULL constraint is applied to a column
  3. When a PRIMARY KEY constraint is applied to a column
  4. When a REFERENCES constraint is applied to a column
  5. When a UNIQUE constraint is applied to a column
     

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

Answer and Explanation

Indexes are created to optimize data retrieval, but they can be automatically created based on constraints applied to tables or columns. This happens when a uniqueness constraint is applied to a column (or a combination of columns). Without an index, when adding new data to a table, you would need to perform a full search to check if data with the same key value exists in that column. With an index, you can simply search the index to verify the existence of the data, which is much more efficient. Therefore, when a UNIQUE constraint or a PRIMARY KEY constraint is applied to a column (or a combination of columns), an index is automatically created on that column.

FOREIGN KEY or REFERENCES is a constraint that there is data with the same key value in another table. The key column on the referenced side must be UNIQUE, so an index exists, but the referencing side does not need to be UNIQUE, so automatic index creation is not performed. Note that if you update or delete the key column on the referenced side, there is a risk of data inconsistency where the referenced destination does not exist, so restrictions are placed on updates and deletions. In cases where such updates and deletions are made, it is desirable to also create an index on the referencing side to efficiently check whether each key is actually being referenced and from which data.
A NOT NULL constraint simply checks that each piece of data is not NULL, so an index is not automatically created.

Therefore, the correct answers are C and E.