PostgreSQL Database Quiz Questions

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

In PostgreSQL, a table must be in First Normal Form (1NF) before it can be in Second Normal Form (2NF).

Q2
True / False

In PostgreSQL, a table is in Second Normal Form (2NF) if all non-key attributes are fully functionally dependent on the primary key.

Q3
True / False

In PostgreSQL, a table with no composite primary key and no partial dependencies is automatically in Second Normal Form (2NF).

Q4
True / False

In PostgreSQL, converting a table to Second Normal Form (2NF) may involve removing columns that depend on only part of a composite primary key.

Q5
True / False

In PostgreSQL, a table in Second Normal Form (2NF) can still have transitive dependencies.

Q6
True / False

In PostgreSQL, a table with a composite primary key is in Second Normal Form (2NF) if every non-key attribute depends on the entire composite primary key.

Q7
True / False

In PostgreSQL, a table that is in Second Normal Form (2NF) must also be in Third Normal Form (3NF).

Q8
True / False

In PostgreSQL, achieving Second Normal Form (2NF) often involves creating additional tables to store data that was originally in a single table.

Q9
True / False

In PostgreSQL, a table with a single-column primary key and no non-key attributes can be considered to be in Second Normal Form (2NF).

Q10
True / False

In PostgreSQL, a table that is in First Normal Form (1NF) but has partial dependencies is in violation of Second Normal Form (2NF).

Q11
Single Choice

In PostgreSQL, which of the following conditions must a table satisfy to be in Second Normal Form (2NF)?

Q12
Single Choice

Consider the following PostgreSQL table orders:

SQL Code
CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 customer_id INT,
 order_date DATE,
 total_amount NUMERIC
);
Is this table in Second Normal Form (2NF)?
Q13
Single Choice

Which of the following is a characteristic of a PostgreSQL table in Second Normal Form?

Q14
Single Choice

Given the following PostgreSQL table student_courses:

SQL Code
CREATE TABLE student_courses (
 student_id INT,
 course_id INT,
 grade CHAR(2),
 PRIMARY KEY (student_id, course_id)
);
Which of the following modifications would ensure the table is in 2NF?
Q15
Single Choice

In PostgreSQL, which of the following tables violates the Second Normal Form (2NF) principle?

Q16
Single Choice

Consider the following PostgreSQL table employees_projects:

SQL Code
CREATE TABLE employees_projects (
 employee_id INT,
 project_id INT,
 project_name VARCHAR(255),
 PRIMARY KEY (employee_id, project_id)
);
Is this table in 2NF, and why?
Q17
Single Choice

Given the following PostgreSQL table sales_data:

SQL Code
CREATE TABLE sales_data (
 product_id INT,
 region_id INT,
 sales_amount NUMERIC,
 region_name VARCHAR(255),
 PRIMARY KEY (product_id, region_id)
);
What should be done to bring this table into 2NF?
Q18
Single Choice

In PostgreSQL, if a table is already in 1NF but not in 2NF, which of the following actions would typically be required?

Q19
Single Choice

Consider a PostgreSQL table product_orders:

SQL Code
CREATE TABLE product_orders (
 order_id INT,
 product_id INT,
 order_date DATE,
 product_name VARCHAR(255),
 PRIMARY KEY (order_id, product_id)
);
Why is this table not in 2NF?
Q20
Single Choice

In PostgreSQL, consider a table inventory with the following structure:

SQL Code
CREATE TABLE inventory (
 warehouse_id INT,
 product_id INT,
 product_name VARCHAR(255),
 quantity INT,
 PRIMARY KEY (warehouse_id, product_id)
);
Which of the following changes should be made to ensure this table is in 2NF?
Q21
Multiple Choice

Which of the following best describes Second Normal Form (2NF) in PostgreSQL?

SQL Code
Consider a table 'student_courses' with columns 'student_id', 'student_name', 'course_id', and 'course_name'. Normalize it to 2NF by ensuring that non-prime attributes are fully dependent on the whole composite primary key.

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 student_courses (
 student_id INT REFERENCES students(student_id),
 course_id INT REFERENCES courses(course_id),
 PRIMARY KEY (student_id, course_id)
);
Q22
Multiple Choice

Which scenario violates Second Normal Form (2NF) in PostgreSQL?

SQL Code
Consider a table 'employee_projects' with columns 'employee_id', 'project_id', 'project_name', and 'employee_name'. Normalize it to 2NF by ensuring non-prime attributes do not depend on only part of a composite key.

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)
);
Q23
Multiple Choice

How would you convert a table from 1NF to 2NF in PostgreSQL?

SQL Code
Given a table 'order_items' with columns 'order_id', 'product_id', 'product_name', and 'order_date', normalize it to 2NF by removing any partial dependencies.

CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 order_date DATE
);

CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 product_name VARCHAR(100)
);

CREATE TABLE order_items (
 order_id INT REFERENCES orders(order_id),
 product_id INT REFERENCES products(product_id),
 PRIMARY KEY (order_id, product_id)
);
Q24
Multiple Choice

Which of the following is a characteristic of a table in 2NF in PostgreSQL?

SQL Code
Consider a table 'course_enrollments' with columns 'student_id', 'course_id', 'enrollment_date', and 'course_instructor'. Normalize it to 2NF by ensuring all non-prime attributes are dependent on the entire primary key.

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

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

CREATE TABLE course_enrollments (
 student_id INT REFERENCES students(student_id),
 course_id INT REFERENCES courses(course_id),
 enrollment_date DATE,
 PRIMARY KEY (student_id, course_id)
);
Q25
Multiple Choice

What are the steps to achieve Second Normal Form (2NF) in a PostgreSQL database?

SQL Code
Normalize a table 'sales_orders' with columns 'order_id', 'product_id', 'product_description', and 'order_quantity' to 2NF by eliminating partial dependencies.

CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 product_description TEXT
);

CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 order_quantity INT
);

CREATE TABLE sales_orders (
 order_id INT REFERENCES orders(order_id),
 product_id INT REFERENCES products(product_id),
 PRIMARY KEY (order_id, product_id)
);
Q26
Multiple Choice

How does 2NF improve data integrity in PostgreSQL?

SQL Code
Normalize a table 'teacher_assignments' with columns 'teacher_id', 'subject_id', 'teacher_name', and 'subject_name' to 2NF by removing any partial dependencies.

CREATE TABLE teachers (
 teacher_id SERIAL PRIMARY KEY,
 teacher_name VARCHAR(100)
);

CREATE TABLE subjects (
 subject_id SERIAL PRIMARY KEY,
 subject_name VARCHAR(100)
);

CREATE TABLE teacher_assignments (
 teacher_id INT REFERENCES teachers(teacher_id),
 subject_id INT REFERENCES subjects(subject_id),
 PRIMARY KEY (teacher_id, subject_id)
);
Q27
Multiple Choice

What is a potential drawback of applying 2NF in PostgreSQL?

SQL Code
Consider a table 'product_reviews' with columns 'review_id', 'product_id', 'reviewer_name', and 'review_text'. Normalize it to 2NF by removing partial dependencies, but consider the potential increase in table joins.

CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 product_name VARCHAR(100)
);

CREATE TABLE reviews (
 review_id SERIAL PRIMARY KEY,
 reviewer_name VARCHAR(100),
 review_text TEXT
);

CREATE TABLE product_reviews (
 product_id INT REFERENCES products(product_id),
 review_id INT REFERENCES reviews(review_id),
 PRIMARY KEY (product_id, review_id)
);
Q28
Multiple Choice

Which of the following is an example of a table that is not in 2NF?

SQL Code
Consider a table 'book_authors' with columns 'book_id', 'author_id', 'book_title', and 'author_name'. Identify the partial dependency and normalize it to 2NF.

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

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

CREATE TABLE book_authors (
 book_id INT REFERENCES books(book_id),
 author_id INT REFERENCES authors(author_id),
 PRIMARY KEY (book_id, author_id)
);
Q29
Multiple Choice

What is the impact of not applying 2NF in a PostgreSQL database?

SQL Code
Normalize a table 'department_employees' with columns 'department_id', 'employee_id', 'department_name', and 'employee_name' to 2NF to eliminate partial dependencies.

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

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

CREATE TABLE department_employees (
 department_id INT REFERENCES departments(department_id),
 employee_id INT REFERENCES employees(employee_id),
 PRIMARY KEY (department_id, employee_id)
);
Q30
Multiple Choice

How can a table in 2NF improve database performance in PostgreSQL?

SQL Code
Normalize a table 'student_grades' with columns 'student_id', 'subject_id', 'grade', and 'student_name' to 2NF by removing partial dependencies.

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

CREATE TABLE subjects (
 subject_id SERIAL PRIMARY KEY,
 subject_name VARCHAR(100)
);

CREATE TABLE student_grades (
 student_id INT REFERENCES students(student_id),
 subject_id INT REFERENCES subjects(subject_id),
 grade CHAR(1),
 PRIMARY KEY (student_id, subject_id)
);