Databases Note
Databases Note
1. Types of Databases
• Relational Databases (RDBMS): Store data in tables with rows and columns.
They use SQL (Structured Query Language) for data manipulation. Examples:
MySQL, PostgreSQL, Oracle, SQL Server.
• NoSQL Databases: Designed for specific data models and have flexible
schemas. Types include document stores (e.g., MongoDB), key-value stores
(e.g., Redis), column-family stores (e.g., Cassandra), and graph databases (e.g.,
Neo4j).
• In-Memory Databases: Store data in RAM for faster access. Example: Redis.
• NewSQL Databases: Combine the scalability of NoSQL with the ACID
guarantees of traditional SQL databases. Example: Google Spanner.
2. Core Concepts
3. SQL Basics
- GROUP BY: Groups rows that have the same values in specified columns into
aggregated data.
```sql
SELECT age, COUNT() FROM students GROUP BY age;
```
- ORDER BY: Sorts the result set of a query by one or more columns.
```sql
SELECT name, age FROM students ORDER BY age DESC;
```
2. Database Design
Database design is crucial for creating an efficient and scalable system. It involves:
Normalization
Normalization is the process of structuring a database to reduce redundancy and
improve data integrity. It involves dividing large tables into smaller, related tables.
Normal Forms:
- First Normal Form (1NF): Ensures that each column contains atomic (indivisible)
values and that each column contains values of a single type.
- Second Normal Form (2NF): Achieved when a table is in 1NF and all non-key columns
are fully dependent on the primary key.
- Third Normal Form (3NF): Achieved when a table is in 2NF and all columns are
dependent only on the primary key.
3. Types of Databases
Let's explore a bit more about different types of databases:
NoSQL Databases
- Document Stores: Store data in documents, often using JSON or BSON format.
Example: MongoDB.
- Key-Value Stores: Store data as a collection of key-value pairs. Example: Redis.
- Column-Family Stores: Store data in columns rather than rows. Example: Apache
Cassandra.
- Graph Databases: Designed to represent and store data with complex relationships.
Example: Neo4j.
4. Practical Considerations
When working with databases, consider the following:
- Scalability: How well the database can handle increasing amounts of data and users.
- Security: Implement access controls, encryption, and regular audits to protect sensitive
data.
- Backup and Recovery: Regularly back up data and have a recovery plan in place to
prevent data loss.
- Performance Tuning: Optimize queries, use indexing effectively, and monitor database
performance.
Would you like to delve deeper into any of these topics, or do you have specific
questions about databases?