PostgreSQL Database Quiz Questions

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

In PostgreSQL, a surrogate key is typically an auto-incremented integer.

Q2
True / False

In PostgreSQL, a surrogate key has no business meaning.

Q3
True / False

In PostgreSQL, a table with a surrogate key cannot have any other candidate keys.

Q4
True / False

In PostgreSQL, using a surrogate key simplifies updates to the database schema.

Q5
True / False

In PostgreSQL, a surrogate key can be used as a foreign key in other tables.

Q6
True / False

In PostgreSQL, a surrogate key must always be an integer.

Q7
True / False

In PostgreSQL, using a surrogate key can prevent duplication of data.

Q8
True / False

In PostgreSQL, surrogate keys can improve the performance of join operations.

Q9
True / False

In PostgreSQL, a surrogate key can be used in combination with a natural key for indexing purposes.

Q10
True / False

In PostgreSQL, a surrogate key should always be preferred over a natural key for primary key usage.

Q11
Single Choice

What is a Surrogate Key in PostgreSQL?

Q12
Single Choice

Which SQL data type is typically used for a Surrogate Key in PostgreSQL?

Q13
Single Choice

What is the main advantage of using a Surrogate Key over a Natural Key in PostgreSQL?

Q14
Single Choice

How do you define a Surrogate Key in a PostgreSQL table using SQL?

Q15
Single Choice

Given the following PostgreSQL table definition, which column is the Surrogate Key?

SQL Code
CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 first_name VARCHAR(50),
 last_name VARCHAR(50)
);
Q16
Single Choice

Why might you prefer a Surrogate Key over a Natural Key in a PostgreSQL database design?

Q17
Single Choice

Which PostgreSQL statement creates a table with a composite Surrogate Key?

Q18
Single Choice

In PostgreSQL, how would you define a table with a Surrogate Key using a UUID instead of a SERIAL?

Q19
Single Choice

Consider the following PostgreSQL table structure:

SQL Code
CREATE TABLE products (
 product_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
 product_name VARCHAR(255) NOT NULL
);
How would you insert a new product into this table?
Q20
Single Choice

Which of the following is the correct approach to migrate a table with a natural key to use a Surrogate Key in PostgreSQL?

Q21
Multiple Choice

What is the primary purpose of using a Surrogate Key in a PostgreSQL table?

SQL Code
Consider a 'users' table with columns 'user_id', 'username', and 'email'. Implement 'user_id' as a Surrogate Key and explain why it is preferred over a Natural Key in this case.

```sql
CREATE TABLE users (
 user_id SERIAL PRIMARY KEY,
 username VARCHAR(100),
 email VARCHAR(255)
);
```
Q22
Multiple Choice

In which scenario is a Surrogate Key preferred over a Natural Key in PostgreSQL?

SQL Code
Given a 'products' table with columns 'product_id', 'sku', and 'product_name', implement 'product_id' as a Surrogate Key. Discuss the benefits of using a Surrogate Key in this scenario.

```sql
CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 sku VARCHAR(50),
 product_name VARCHAR(255)
);
```
Q23
Multiple Choice

How does using a Surrogate Key impact database indexing and performance?

SQL Code
Consider a 'transactions' table with columns 'transaction_id', 'account_number', and 'transaction_date'. Implement 'transaction_id' as a Surrogate Key and explain how it impacts indexing and query performance.

```sql
CREATE TABLE transactions (
 transaction_id SERIAL PRIMARY KEY,
 account_number VARCHAR(20),
 transaction_date DATE
);
```
Q24
Multiple Choice

What are the potential drawbacks of using Surrogate Keys in PostgreSQL?

SQL Code
Given a 'customers' table with columns 'customer_id', 'customer_code', and 'customer_name', implement 'customer_id' as a Surrogate Key. Discuss the potential drawbacks of this approach.

```sql
CREATE TABLE customers (
 customer_id SERIAL PRIMARY KEY,
 customer_code VARCHAR(50),
 customer_name VARCHAR(255)
);
```
Q25
Multiple Choice

Why might you use a composite key in conjunction with a Surrogate Key in PostgreSQL?

SQL Code
Consider a 'orders' table with columns 'order_id', 'customer_id', 'order_date', and 'order_number'. Implement 'order_id' as a Surrogate Key and explain when you might use a composite key alongside it.

```sql
CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 customer_id INT,
 order_date DATE,
 order_number VARCHAR(20)
);
```
Q26
Multiple Choice

How does a Surrogate Key differ from a Natural Key in terms of data integrity?

SQL Code
Given an 'employees' table with columns 'employee_id', 'national_id', and 'full_name', implement 'employee_id' as a Surrogate Key. Discuss the impact of this choice on data integrity compared to using 'national_id' as a Natural Key.

```sql
CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 national_id VARCHAR(20),
 full_name VARCHAR(255)
);
```
Q27
Multiple Choice

What considerations should be made when choosing between a Surrogate Key and a Natural Key in PostgreSQL?

SQL Code
Consider a 'departments' table with columns 'department_id', 'department_code', and 'department_name'. Implement 'department_id' as a Surrogate Key and discuss the considerations when choosing between this and using 'department_code' as a Natural Key.

```sql
CREATE TABLE departments (
 department_id SERIAL PRIMARY KEY,
 department_code VARCHAR(10) UNIQUE,
 department_name VARCHAR(100)
);
```
Q28
Multiple Choice

In which situations is it advisable to avoid using Surrogate Keys in PostgreSQL?

SQL Code
Given a 'projects' table with columns 'project_id', 'project_code', and 'project_name', explain when it might be advisable to avoid using a Surrogate Key like 'project_id' and instead rely on 'project_code' as a Natural Key.

```sql
CREATE TABLE projects (
 project_id SERIAL PRIMARY KEY,
 project_code VARCHAR(20) UNIQUE,
 project_name VARCHAR(255)
);
```
Q29
Multiple Choice

How does the choice of Surrogate Key impact database migrations and data warehousing?

SQL Code
Consider a 'sales' table with columns 'sale_id', 'invoice_number', and 'sale_date'. Implement 'sale_id' as a Surrogate Key and discuss the implications for database migrations and data warehousing.

```sql
CREATE TABLE sales (
 sale_id SERIAL PRIMARY KEY,
 invoice_number VARCHAR(20),
 sale_date DATE
);
```
Q30
Multiple Choice

What are the advantages of using a sequence-based Surrogate Key in PostgreSQL?

SQL Code
Given an 'invoices' table with columns 'invoice_id', 'invoice_number', and 'total_amount', implement 'invoice_id' as a sequence-based Surrogate Key. Discuss the advantages of this approach.

```sql
CREATE TABLE invoices (
 invoice_id SERIAL PRIMARY KEY,
 invoice_number VARCHAR(20),
 total_amount NUMERIC(10, 2)
);
```