Q1
True / FalseIn PostgreSQL, a table must be in Second Normal Form (2NF) before it can be in Third Normal Form (3NF).
A table must first satisfy all the requirements of 2NF before it can be normalized to 3NF.
Q2
True / FalseIn PostgreSQL, a table is in Third Normal Form (3NF) if it has no transitive dependencies.
3NF requires that there are no transitive dependencies, meaning non-key attributes must not depend on other non-key attributes.
Q3
True / FalseIn PostgreSQL, a table with a single-column primary key and no transitive dependencies is automatically in Third Normal Form (3NF).
If there are no transitive dependencies and the table meets 2NF, it is automatically in 3NF.
Q4
True / FalseIn PostgreSQL, achieving Third Normal Form (3NF) often involves moving columns to new tables to eliminate transitive dependencies.
To achieve 3NF, columns involved in transitive dependencies are moved to new tables where they can form direct relationships with primary keys.
Q5
True / FalseIn PostgreSQL, a table in Third Normal Form (3NF) cannot have any redundant data.
While 3NF reduces redundancy by eliminating transitive dependencies, it does not necessarily eliminate all redundancy. Higher normal forms address other types of redundancy.
Q6
True / FalseIn PostgreSQL, if a non-key attribute depends on another non-key attribute, the table is not in Third Normal Form (3NF).
3NF requires that non-key attributes do not depend on other non-key attributes, only on the primary key.
Q7
True / FalseIn PostgreSQL, a table that meets the requirements of Boyce-Codd Normal Form (BCNF) is also in Third Normal Form (3NF).
BCNF is a stricter version of 3NF. Therefore, if a table is in BCNF, it also satisfies the requirements of 3NF.
Q8
True / FalseIn PostgreSQL, a table with a composite primary key can be in Third Normal Form (3NF) even if some non-key attributes are partially dependent on the primary key.
Partial dependencies violate 2NF. Since 3NF requires 2NF compliance and no transitive dependencies, partial dependencies are not allowed in 3NF.
Q9
True / FalseIn PostgreSQL, achieving Third Normal Form (3NF) ensures that all non-key attributes are only dependent on the primary key.
3NF ensures that non-key attributes are fully functionally dependent only on the primary key and not on any other non-key attributes.
Q10
True / FalseIn PostgreSQL, a table in Third Normal Form (3NF) can still have multi-valued attributes as long as they do not create transitive dependencies.
Multi-valued attributes violate 1NF, which is a prerequisite for 3NF. Therefore, a table in 3NF cannot have multi-valued attributes.
Q21
Multiple ChoiceWhich of the following best describes Third Normal Form (3NF) in PostgreSQL?
SQL Code
Consider a table 'employee_details' with columns 'employee_id', 'employee_name', 'department_id', 'department_name', and 'location'. Normalize it to 3NF by ensuring that all non-key attributes are non-transitively dependent on the primary key.
```sql
CREATE TABLE departments (
department_id SERIAL PRIMARY KEY,
department_name VARCHAR(100),
location VARCHAR(100)
);
CREATE TABLE employees (
employee_id SERIAL PRIMARY KEY,
employee_name VARCHAR(100),
department_id INT REFERENCES departments(department_id)
);
```
Third Normal Form (3NF) ensures that all non-key attributes are non-transitively dependent on the primary key. This means that attributes must depend directly on the primary key, rather than through another non-key attribute, reducing redundancy and eliminating transitive dependencies.
Q23
Multiple ChoiceHow would you convert a table from 2NF to 3NF in PostgreSQL?
SQL Code
Given a table 'project_assignments' with columns 'project_id', 'employee_id', 'employee_name', and 'department_name', normalize it to 3NF by removing any transitive dependencies.
```sql
CREATE TABLE departments (
department_id SERIAL PRIMARY KEY,
department_name VARCHAR(100)
);
CREATE TABLE employees (
employee_id SERIAL PRIMARY KEY,
employee_name VARCHAR(100),
department_id INT REFERENCES departments(department_id)
);
CREATE TABLE projects (
project_id SERIAL PRIMARY KEY
);
CREATE TABLE project_assignments (
project_id INT REFERENCES projects(project_id),
employee_id INT REFERENCES employees(employee_id),
PRIMARY KEY (project_id, employee_id)
);
```
To convert a table from 2NF to 3NF, you must remove transitive dependencies by ensuring that non-key attributes depend directly on the primary key and not on another non-key attribute.
Q28
Multiple ChoiceWhich of the following is an example of a table that is not in 3NF?
SQL Code
Consider a table 'book_inventory' with columns 'book_id', 'book_title', 'publisher_name', and 'publisher_address'. Identify the transitive dependency and normalize it to 3NF.
```sql
CREATE TABLE books (
book_id SERIAL PRIMARY KEY,
book_title VARCHAR(100)
);
CREATE TABLE publishers (
publisher_id SERIAL PRIMARY KEY,
publisher_name VARCHAR(100),
publisher_address TEXT
);
CREATE TABLE book_inventory (
book_id INT REFERENCES books(book_id),
publisher_id INT REFERENCES publishers(publisher_id),
PRIMARY KEY (book_id, publisher_id)
);
```
A table is not in 3NF if it has transitive dependencies, where a non-key attribute depends on another non-key attribute instead of directly on the primary key, leading to redundancy and potential data anomalies.
Q29
Multiple ChoiceWhat is the impact of not applying 3NF in a PostgreSQL database?
SQL Code
Normalize a table 'course_enrollments' with columns 'course_id', 'student_id', 'course_name', and 'instructor_name' to 3NF to eliminate transitive dependencies.
```sql
CREATE TABLE courses (
course_id SERIAL PRIMARY KEY,
course_name VARCHAR(100)
);
CREATE TABLE instructors (
instructor_id SERIAL PRIMARY KEY,
instructor_name VARCHAR(100)
);
CREATE TABLE course_enrollments (
course_id INT REFERENCES courses(course_id),
student_id INT REFERENCES students(student_id),
instructor_id INT REFERENCES instructors(instructor_id),
PRIMARY KEY (course_id, student_id)
);
```
Not applying 3NF can lead to transitive 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 3NF improve database performance in PostgreSQL?
SQL Code
Normalize a table 'employee_salaries' with columns 'employee_id', 'salary', 'department_name', and 'manager_name' to 3NF by removing transitive dependencies.
```sql
CREATE TABLE employees (
employee_id SERIAL PRIMARY KEY,
salary NUMERIC(10, 2)
);
CREATE TABLE departments (
department_id SERIAL PRIMARY KEY,
department_name VARCHAR(100)
);
CREATE TABLE managers (
manager_id SERIAL PRIMARY KEY,
manager_name VARCHAR(100)
);
CREATE TABLE employee_salaries (
employee_id INT REFERENCES employees(employee_id),
department_id INT REFERENCES departments(department_id),
manager_id INT REFERENCES managers(manager_id),
PRIMARY KEY (employee_id, department_id)
);
```
By applying 3NF, 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.