PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 8 - RDBMS Concepts
Lesson Content Link:ERD (Data Model)
Current Quiz Count:30
Progress
0%
Q1
True / False

In PostgreSQL, an ERD (Entity-Relationship Diagram) helps visualize the database schema.

Q2
True / False

In PostgreSQL, entities in an ERD correspond to tables in the database.

Q3
True / False

In PostgreSQL, primary keys in an ERD are used to uniquely identify each row in a table.

Q4
True / False

In PostgreSQL, relationships in an ERD are implemented using foreign keys.

Q5
True / False

In PostgreSQL, an ERD cannot represent many-to-many relationships.

Q6
True / False

In PostgreSQL, each attribute in an ERD must correspond to a unique column in a table.

Q7
True / False

In PostgreSQL, ERDs can include constraints such as unique, not null, and check constraints.

Q8
True / False

In PostgreSQL, an ERD can represent hierarchical data structures using recursive relationships.

Q9
True / False

In PostgreSQL, an ERD cannot include views or materialized views.

Q10
True / False

In PostgreSQL, an ERD must be strictly adhered to and cannot be modified once the database is created.

Q11
Single Choice

Which of the following best describes an ERD (Entity-Relationship Diagram)?

Q12
Single Choice

In PostgreSQL, which of the following can be directly derived from an ERD?

Q13
Single Choice

Which symbol in an ERD represents the relationship between entities in PostgreSQL?

Q14
Single Choice

Consider the following PostgreSQL entities in an ERD: Entity Customer has attributes CustomerID and Name. Entity Order has attributes OrderID and OrderDate. What type of relationship is likely between Customer and Order?

Q15
Single Choice

Given the ERD relationship between Product and Category where each product belongs to one category and each category can have multiple products, which of the following SQL statements correctly creates the Product table in PostgreSQL?

Q16
Single Choice

In PostgreSQL, if an ERD shows a Student entity related to a Class entity in a many-to-many relationship, which additional table is necessary?

Q17
Single Choice

In an ERD for PostgreSQL, how would you represent a weak entity OrderItem that depends on the Order entity, with OrderItemID and OrderID as attributes?

Q18
Single Choice

Which of the following SQL statements correctly represents the creation of a table from an ERD with a one-to-one relationship in PostgreSQL?

Q19
Single Choice

When translating an ERD into a PostgreSQL schema, which of the following best describes how to represent a ternary relationship between three entities: Employee, Project, and Task?

Q20
Single Choice

In a PostgreSQL ERD, which of the following best represents a scenario where an entity has a recursive relationship?

Q21
Multiple Choice

What is the purpose of an Entity-Relationship Diagram (ERD) in database design?

SQL Code
You have a simple ERD with two entities: 'customers' and 'orders'. Write a SQL script to create the corresponding tables in PostgreSQL, ensuring the 'orders' table references the 'customers' table.

```sql
CREATE TABLE customers (
 customer_id SERIAL PRIMARY KEY,
 customer_name VARCHAR(100)
);

CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 order_date DATE,
 customer_id INT REFERENCES customers(customer_id)
);
```
Q22
Multiple Choice

What type of relationship is represented between two entities when a foreign key is used?

SQL Code
CREATE TABLE students (
 student_id SERIAL PRIMARY KEY,
 student_name VARCHAR(100)
);

CREATE TABLE courses (
 course_id SERIAL PRIMARY KEY,
 course_name VARCHAR(100)
);

CREATE TABLE enrollments (
 enrollment_id SERIAL PRIMARY KEY,
 student_id INT REFERENCES students(student_id),
 course_id INT REFERENCES courses(course_id)
);
Q23
Multiple Choice

How would you represent a many-to-many relationship in an ERD?

SQL Code
Given an ERD with 'authors' and 'books' where each author can write multiple books and each book can have multiple authors, write a SQL script to implement this relationship in PostgreSQL.

```sql
CREATE TABLE authors (
 author_id SERIAL PRIMARY KEY,
 author_name VARCHAR(100)
);

CREATE TABLE books (
 book_id SERIAL PRIMARY KEY,
 book_title VARCHAR(100)
);

CREATE TABLE author_books (
 author_id INT REFERENCES authors(author_id),
 book_id INT REFERENCES books(book_id),
 PRIMARY KEY (author_id, book_id)
);
```
Q24
Multiple Choice

What is the significance of primary keys in an ERD?

SQL Code
Create a table 'departments' with a primary key 'department_id' and a unique constraint on the 'department_name'. Write a SQL script to create this table in PostgreSQL.

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

In an ERD, what does a 'crow's foot' notation represent?

SQL Code
Given an ERD that shows a one-to-many relationship between 'categories' and 'products', write a SQL script to create these tables with appropriate foreign key constraints in PostgreSQL.

```sql
CREATE TABLE categories (
 category_id SERIAL PRIMARY KEY,
 category_name VARCHAR(100)
);

CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 product_name VARCHAR(100),
 category_id INT REFERENCES categories(category_id)
);
```
Q26
Multiple Choice

How would you model a self-referencing relationship in an ERD?

SQL Code
Create a 'categories' table where each category can have a parent category. Write a SQL script to implement this self-referencing relationship in PostgreSQL.

```sql
CREATE TABLE categories (
 category_id SERIAL PRIMARY KEY,
 category_name VARCHAR(100),
 parent_category_id INT REFERENCES categories(category_id)
);
```
Q27
Multiple Choice

What is the role of composite keys in an ERD?

SQL Code
Given an ERD with 'employees' and 'projects' where each employee can work on multiple projects and each project can have multiple employees, write a SQL script to implement this many-to-many relationship using a composite key in PostgreSQL.

```sql
CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 employee_name VARCHAR(100)
);

CREATE TABLE projects (
 project_id SERIAL PRIMARY KEY,
 project_name VARCHAR(100)
);

CREATE TABLE employee_projects (
 employee_id INT REFERENCES employees(employee_id),
 project_id INT REFERENCES projects(project_id),
 PRIMARY KEY (employee_id, project_id)
);
```
Q28
Multiple Choice

How does normalization relate to ERD in database design?

SQL Code
You have an ERD with entities 'students' and 'courses'. To avoid redundancy, write a SQL script to normalize the design by creating a 'enrollments' table that stores the relationships between students and courses.

```sql
CREATE TABLE students (
 student_id SERIAL PRIMARY KEY,
 student_name VARCHAR(100)
);

CREATE TABLE courses (
 course_id SERIAL PRIMARY KEY,
 course_name VARCHAR(100)
);

CREATE TABLE enrollments (
 enrollment_id SERIAL PRIMARY KEY,
 student_id INT REFERENCES students(student_id),
 course_id INT REFERENCES courses(course_id)
);
```
Q29
Multiple Choice

What are the key components of an ERD?

SQL Code
Create an ERD for a 'library' database with entities: 'books', 'authors', and 'borrowers'. Write a SQL script to create these tables with primary and foreign key constraints in PostgreSQL.

```sql
CREATE TABLE books (
 book_id SERIAL PRIMARY KEY,
 book_title VARCHAR(100),
 author_id INT REFERENCES authors(author_id)
);

CREATE TABLE authors (
 author_id SERIAL PRIMARY KEY,
 author_name VARCHAR(100)
);

CREATE TABLE borrowers (
 borrower_id SERIAL PRIMARY KEY,
 borrower_name VARCHAR(100)
);
```
Q30
Multiple Choice

How do you represent optional relationships in an ERD?

SQL Code
You have an ERD with 'employees' and 'managers' where each employee may or may not have a manager. Write a SQL script to implement this optional relationship in PostgreSQL.

```sql
CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 employee_name VARCHAR(100),
 manager_id INT REFERENCES employees(employee_id) ON DELETE SET NULL
);
```