Q1
True / FalseIn PostgreSQL, a table must be in First Normal Form (1NF) before it can be in Second Normal Form (2NF).
A table must first satisfy all the requirements of 1NF before it can be normalized to 2NF.
Q2
True / FalseIn PostgreSQL, a table is in Second Normal Form (2NF) if all non-key attributes are fully functionally dependent on the primary key.
2NF requires that all non-key attributes are fully dependent on the entire primary key, not just part of it.
Q3
True / FalseIn PostgreSQL, a table with no composite primary key and no partial dependencies is automatically in Second Normal Form (2NF).
If a table has a single-column primary key, it cannot have partial dependencies, and if it meets 1NF, it is automatically in 2NF.
Q4
True / FalseIn PostgreSQL, converting a table to Second Normal Form (2NF) may involve removing columns that depend on only part of a composite primary key.
To achieve 2NF, columns that depend only on part of a composite primary key must be moved to another table where they are fully dependent on the new primary key.
Q5
True / FalseIn PostgreSQL, a table in Second Normal Form (2NF) can still have transitive dependencies.
2NF does not address transitive dependencies; it only eliminates partial dependencies.
Q6
True / FalseIn 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.
2NF requires that non-key attributes depend on the whole composite primary key, not just a part of it.
Q7
True / FalseIn PostgreSQL, a table that is in Second Normal Form (2NF) must also be in Third Normal Form (3NF).
A table in 2NF is not necessarily in 3NF. 2NF eliminates partial dependencies, while 3NF also eliminates transitive dependencies.
Q8
True / FalseIn PostgreSQL, achieving Second Normal Form (2NF) often involves creating additional tables to store data that was originally in a single table.
Normalizing to 2NF may require splitting the original table into multiple tables to eliminate partial dependencies.
Q9
True / FalseIn PostgreSQL, a table with a single-column primary key and no non-key attributes can be considered to be in Second Normal Form (2NF).
If a table has a single-column primary key and no non-key attributes, it meets the requirements for 2NF by default.
Q10
True / FalseIn PostgreSQL, a table that is in First Normal Form (1NF) but has partial dependencies is in violation of Second Normal Form (2NF).
2NF requires that all non-key attributes are fully functionally dependent on the entire primary key. Partial dependencies violate this requirement.
Q16
Single ChoiceConsider 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?
The table violates 2NF because project_name is only dependent on project_id, not the full composite key.
Q21
Multiple ChoiceWhich 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)
);
Second Normal Form (2NF) requires that all non-prime attributes are fully functionally dependent on the entire primary key, not just part of it. This eliminates partial dependencies, ensuring better data integrity.
Q22
Multiple ChoiceWhich 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)
);
A table violates 2NF if it has partial dependencies, where a non-prime attribute is dependent on only part of a composite primary key. This means that the attribute does not rely on the entire key, leading to redundancy.
Q23
Multiple ChoiceHow 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)
);
To convert a table from 1NF to 2NF, you must remove partial dependencies by ensuring that all non-prime attributes are fully dependent on the entire composite key, not just part of it.
Q24
Multiple ChoiceWhich 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)
);
A table in 2NF has no partial dependencies, meaning that every non-prime attribute is fully dependent on the whole primary key. This ensures that data is stored in a more structured and efficient manner.
Q25
Multiple ChoiceWhat 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)
);
To achieve 2NF, first ensure that the table is in 1NF, then remove any partial dependencies by splitting the table into smaller tables where non-prime attributes depend on the entire primary key.
Q26
Multiple ChoiceHow 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)
);
2NF improves data integrity by eliminating partial dependencies, which reduces redundancy and ensures that each piece of data is stored in only one place, thereby reducing the risk of data anomalies.
Q27
Multiple ChoiceWhat 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)
);
While 2NF reduces redundancy and improves data integrity, it can also lead to more complex queries due to an increased number of table joins. This can potentially affect database performance.
Q28
Multiple ChoiceWhich 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)
);
A table is not in 2NF if it has partial dependencies, where a non-prime attribute depends on only a part of the composite key, leading to redundancy and potential data anomalies.
Q29
Multiple ChoiceWhat 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)
);
Not applying 2NF can lead to partial dependencies, which result in redundancy, increased storage requirements, and potential data anomalies during insert, update, or delete operations.
Q30
Multiple ChoiceHow 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)
);
By applying 2NF, you reduce data redundancy and ensure that data is stored more efficiently, which can improve database performance, particularly in terms of data retrieval and update operations.