Rel Dbs
Rel Dbs
### Tables
- Tables are the basic structure in a relational database, each containing rows and
columns.
- Each row represents a record (or tuple) and each column represents an attribute
(or field) of the record.
- The intersection of a row and column is a specific data value.
### Keys
- Keys are used to uniquely identify each row in a table.
- Primary Key: A column (or a set of columns) that uniquely identifies each row in
the table.
- Foreign Key: A set of columns in a table that refers to the primary key in
another table. It establishes a link between the two tables.
Example:
SELECT first_name, last_name FROM employees WHERE department = 'IT';
### JOINs
Joins are used to retrieve data from multiple tables based on a related column
between them. Common types of joins include INNER JOIN, LEFT JOIN, and RIGHT JOIN.
Example:
SELECT orders.order_id, customers.customer_name
FROM orders
INNER JOIN customers ON orders.customer_id = customers.customer_id;
## Data Integrity
Relational databases enforce data integrity through various constraints, including:
- Entity Integrity: Ensuring each row in a table is uniquely identifiable through a
primary key.
- Referential Integrity: Ensuring the consistency of data between related tables
using foreign keys.
- Domain Integrity: Enforcing the validity of data based on defined data types and
constraints.
## Normalization
Normalization is the process of organizing the columns and tables of a relational
database to minimize data redundancy and dependency. This helps to ensure data
integrity and reduce anomalies during data manipulation.
## Conclusion
Relational databases have been a foundational technology for managing structured
data. They provide a powerful and flexible way to store and retrieve data while
maintaining data integrity. Understanding the principles of relational databases is
crucial for anyone working with data in IT, development, or related fields.
Remember, these are just the basics! There's a lot more to explore in the world of
relational databases.