In DDL, how do you declare a column as the primary key?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

In DDL, how do you declare a column as the primary key?

Explanation:
Declaring a column as the primary key is done by adding PRIMARY KEY directly after the column’s datatype in its definition. This inline syntax marks that column as the table’s primary key, which means it uniquely identifies each row and is implicitly NOT NULL in most databases. Other options either enforce uniqueness without making a column the primary key, or try to declare a table constraint without the proper syntax for a named constraint. For example, UNIQUE ensures unique values but doesn’t designate the primary key; a table-level constraint like PRIMARY KEY (column) usually requires a name (CONSTRAINT name PRIMARY KEY (column)), not just CONSTRAINT PRIMARY KEY (column).

Declaring a column as the primary key is done by adding PRIMARY KEY directly after the column’s datatype in its definition. This inline syntax marks that column as the table’s primary key, which means it uniquely identifies each row and is implicitly NOT NULL in most databases.

Other options either enforce uniqueness without making a column the primary key, or try to declare a table constraint without the proper syntax for a named constraint. For example, UNIQUE ensures unique values but doesn’t designate the primary key; a table-level constraint like PRIMARY KEY (column) usually requires a name (CONSTRAINT name PRIMARY KEY (column)), not just CONSTRAINT PRIMARY KEY (column).

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy