Database Basics

In a relational database table, which condition must the column (or set of columns) designated as the primary key satisfy?

  1. AIts values must be numbers
  2. BIt must be the first column of the table
  3. CIts values must not be duplicated within the table and must not include NULL
Show answer and explanation

Answer: C. Its values must not be duplicated within the table and must not include NULL

A primary key is a column, or set of columns, used to uniquely identify one row in a table. Its values therefore must not duplicate those of any other row (uniqueness), and NULL, which represents an unknown value, is not allowed either (NOT NULL). When PRIMARY KEY is specified in an SQL CREATE TABLE statement, the DBMS (database management system) enforces these two constraints, and any operation that tries to insert a duplicate value or NULL fails with an error. A primary key may hold numbers such as employee numbers or character strings, and there is no rule about its column position. A minimal set of columns that can uniquely identify a row is called a candidate key, and the primary key is the one chosen from the candidate keys.

  • A. A primary key can be a character string; it does not have to be a number.
  • B. A primary key can be any column of the table; its position does not matter.
  • C. Correct. Being unique and free of NULL are the conditions for a primary key.
Practice this topic Back to topic

Related calculators

Books on Database Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Database Basics questions

  1. In an employee table (emp_no, email, name, dept), both emp_no and email are different for every employee and never NULL. Name and dept may be the same as those of other employees. Which lists all the candidate keys of this table?
  2. An enrollment table (student_no, course_no, grade) records which student took which course and with what grade. One student takes several courses, and one course is taken by several students. If the same student never registers for the same course twice, which is an appropriate primary key for this table?
  3. The primary key of a customer table (cust_id, name) is cust_id, and cust_id in an orders table (order_id, cust_id) is defined as a foreign key referring to cust_id in the customer table. The customer table contains only the rows with cust_id 'C1' and 'C2'. What happens when INSERT INTO orders VALUES ('O9', 'C5') is executed in this state?
  4. SQL statements are divided into the data definition language (DDL), data manipulation language (DML) and data control language (DCL). Which one is classified as DDL?
  5. A product table has five rows of (name, price): (pen, 120), (notebook, 250), (eraser, 80), (file, 300), (ruler, 150). Which shows, in order, the rows returned by SELECT name FROM product WHERE price >= 150 ORDER BY price DESC?