Sample Exam Questions

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

Sample Question

3.35

Choose two correct syntaxes for creating a table 'test' with the column 'id' as the primary key.


  1. create table test (primary key id integer, val varchar(50));

  2. create table test (id integer primary key, val varchar(50));

  3. create table test (id integer, val varchar(50), constraint id primary key);

  4. create table test (id integer, val varchar(50), primary key (id));

  5. create table test (id integer, val varchar(50), primary key = id);

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

Answer and Explanation

The basic syntax for creating a table with the CREATE TABLE command is as follows:
create table table_name (column_definition, column_definition... [, table_constraints])


There are constraints that can only be specified as column constraints, such as the NOT NULL constraint, constraints that can only be specified as table constraints, such as the CHECK constraint, and constraints that can be specified as either column or table constraints, such as the PRIMARY KEY, UNIQUE, and foreign key constraints.
Column constraints are written by appending the constraint to the column definition, which consists of a column name and data type. For a primary key, you simply write 'primary key'.
Table constraints are written after all column definitions, separated by a comma. For a primary key, you specify it in the format 'primary key (key_column)'. If the primary key is a single column, it can be written as either a column constraint or a table constraint. However, if the primary key is a combination of multiple columns, it must be written as a table constraint.

Therefore, the correct answers are B and D.