sdfsdf
sdfsdf
PDF: Here are the complete answers to the Database Management Systems (DBMS)
questions as outlined in the document:
1. **Explain normalization and why it is important. Describe 1NF, 2NF, and 3NF.**
- **Normalization** is the process of organizing data in a database to reduce
redundancy and improve data integrity. It involves dividing large tables into
smaller ones and defining relationships between them.
- **1NF (First Normal Form)**: A table is in 1NF if it contains only atomic
(indivisible) values and each entry in a column is of the same data type. There
should be no repeating groups or arrays.
- **2NF (Second Normal Form)**: A table is in 2NF if it is in 1NF and all non-
key attributes are fully functionally dependent on the primary key. This means that
no partial dependency of any column on the primary key should exist.
- **3NF (Third Normal Form)**: A table is in 3NF if it is in 2NF and all the
attributes are functionally dependent only on the primary key. There should be no
transitive dependency, meaning non-key attributes should not depend on other non-
key attributes.
6. **What are joins in SQL? Explain INNER JOIN and LEFT JOIN with examples.**
- **Joins** are used to combine rows from two or more tables based on a related
column between them.
- **INNER JOIN**: Returns records that have matching values in both tables.
```sql
SELECT employees.name, departments.department_name
FROM employees
INNER JOIN departments ON employees.department_id = departments.id;
```
- **LEFT JOIN**: Returns all records from the left table and the matched
records from the right table. If there is no match, NULL values are returned for
columns from the right table.
```sql
SELECT employees.name, departments.department_name
FROM employees
LEFT JOIN departments ON employees.department_id = departments.id;
```
9. **Explain the difference between SQL and NoSQL databases with examples.**
- **SQL Databases**: These are relational databases that use structured query
language (SQL) for defining and manipulating data. They are table-based and enforce
a schema. Examples include MySQL, PostgreSQL, and Oracle.
- **NoSQL Databases**: These are non-relational databases that can store
unstructured or semi-structured data. They are more flexible and can handle large
volumes of data. Examples include MongoDB, Cassandra, and Redis.
11. **Write an SQL query to find all employees with salaries above the average.**
```sql
SELECT * FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
```