PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 8 - RDBMS Concepts
Lesson Content Link:Primary Key
Current Quiz Count:30
Progress
0%
Q1
True / False

In PostgreSQL, a primary key uniquely identifies each record in a table.

Q2
True / False

A table in PostgreSQL can have more than one primary key.

Q3
True / False

In PostgreSQL, a primary key column cannot contain NULL values.

Q4
True / False

In PostgreSQL, a primary key constraint automatically creates a unique index on the primary key column(s).

Q5
True / False

In PostgreSQL, you can define a primary key on an existing table using the ALTER TABLE statement.

Q6
True / False

PostgreSQL allows defining a primary key on a column that already has a unique constraint.

Q7
True / False

In PostgreSQL, a composite primary key can consist of columns from different tables.

Q8
True / False

Dropping a primary key constraint in PostgreSQL will automatically drop any associated indexes.

Q9
True / False

In PostgreSQL, you can use the USING INDEX clause to specify a custom index for enforcing a primary key constraint.

Q10
True / False

In PostgreSQL, defining a primary key on a table that already contains duplicate values in the target column(s) will succeed without errors.

Q11
Single Choice

What is the main purpose of a Primary Key in a PostgreSQL table?

Q12
Single Choice

Which SQL command is used to define a Primary Key when creating a new table in PostgreSQL?

Q13
Single Choice

In PostgreSQL, can a table have more than one Primary Key?

Q14
Single Choice

How do you add a Primary Key to an existing table in PostgreSQL?

Q15
Single Choice

Consider the following PostgreSQL SQL statement:

SQL Code
CREATE TABLE employees (
 emp_id SERIAL,
 first_name VARCHAR(50),
 last_name VARCHAR(50),
 PRIMARY KEY (emp_id)
);
What does the PRIMARY KEY (emp_id) line do?
Q16
Single Choice

What happens if you try to insert a duplicate value in a column that is defined as a Primary Key in PostgreSQL?

Q17
Single Choice

Given the following PostgreSQL SQL statement:

SQL Code
CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 customer_id INT,
 order_date DATE,
 PRIMARY KEY (order_id)
);
What will happen if you attempt to execute this command?
Q18
Single Choice

How can you define a composite Primary Key in PostgreSQL using SQL?

Q19
Single Choice

Consider the following PostgreSQL SQL command:

SQL Code
CREATE TABLE enrollment (
 student_id INT,
 course_id INT,
 PRIMARY KEY (student_id, course_id)
);
What type of key is defined in this table?
Q20
Single Choice

In PostgreSQL, which of the following is a correct method to remove a Primary Key constraint from a table?

Q21
Multiple Choice

Which statement best describes a primary key in an RDBMS like PostgreSQL?

SQL Code
CREATE TABLE students (
 student_id SERIAL PRIMARY KEY,
 first_name VARCHAR(50),
 last_name VARCHAR(50)
);
Q22
Multiple Choice

What is the significance of using the SERIAL keyword in defining a primary key in PostgreSQL?

SQL Code
CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 order_date DATE,
 customer_id INT
);
Q23
Multiple Choice

How does a primary key contribute to database normalization in an RDBMS?

SQL Code
CREATE TABLE departments (
 department_id SERIAL PRIMARY KEY,
 department_name VARCHAR(100)
);

CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 first_name VARCHAR(50),
 department_id INT REFERENCES departments(department_id)
);
Q24
Multiple Choice

Can a table in PostgreSQL have more than one primary key? Select the correct statements.

SQL Code
CREATE TABLE projects (
 project_id SERIAL PRIMARY KEY,
 project_name VARCHAR(100),
 manager_id INT
);
Q25
Multiple Choice

Which of the following constraints is automatically applied to a primary key in PostgreSQL?

SQL Code
CREATE TABLE inventory (
 item_id SERIAL PRIMARY KEY,
 item_name VARCHAR(100),
 quantity INT
);
Q26
Multiple Choice

How can a primary key be altered in an existing PostgreSQL table?

SQL Code
CREATE TABLE sales (
 sale_id INT,
 transaction_id INT,
 sale_date DATE
);

ALTER TABLE sales ADD PRIMARY KEY (sale_id);
ALTER TABLE sales DROP CONSTRAINT sales_pkey;
ALTER TABLE sales ADD PRIMARY KEY (transaction_id);
Q27
Multiple Choice

In a composite primary key, how does PostgreSQL ensure the uniqueness of records?

SQL Code
CREATE TABLE enrollments (
 student_id INT,
 course_id INT,
 enrollment_date DATE,
 PRIMARY KEY (student_id, course_id)
);
Q28
Multiple Choice

What happens if an attempt is made to insert a duplicate value into a primary key column in PostgreSQL?

SQL Code
CREATE TABLE members (
 member_id SERIAL PRIMARY KEY,
 member_name VARCHAR(100)
);

INSERT INTO members (member_name) VALUES ('Alice');
INSERT INTO members (member_id, member_name) VALUES (1, 'Bob');
Q29
Multiple Choice

Can a primary key in PostgreSQL be created on a column with NULL values?

SQL Code
CREATE TABLE libraries (
 library_id SERIAL PRIMARY KEY,
 library_name VARCHAR(100),
 location VARCHAR(100)
);

INSERT INTO libraries (library_name, location) VALUES ('Central Library', NULL);
ALTER TABLE libraries ADD PRIMARY KEY (location);
Q30
Multiple Choice

What is the role of a primary key in establishing relationships between tables in PostgreSQL?

SQL Code
CREATE TABLE departments (
 department_id SERIAL PRIMARY KEY,
 department_name VARCHAR(100)
);

CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 department_id INT REFERENCES departments(department_id)
);