Topic 1 - Introduction to Database
Topic 1 - Introduction to Database
Stored Procedures
Stored procedures are precompiled collections of SQL statements that can be executed as
a single unit. They are used to perform complex operations or enforce business logic.
Example: A stored procedure might handle the process of updating customer records and
generating a confirmation email.
Triggers
Triggers are automatic actions that are executed in response to certain events on a table,
such as inserts, updates, or deletes.
Example: A trigger might automatically update the "LastModifiedDate" field when a record in
the "Students" table is updated.
Constraints
Constraints are rules applied to fields in a table to enforce data integrity.
They enforce data integrity and prevent invalid data entry.
For example, a unique constraint on the "Email" column to ensure no two customers have
the same email address.
Constraints include;
a) Primary Key
- Ensures each record is unique and cannot be NULL.
- Used to identify each row in a table uniquely.
- A company’s employee database must ensure that each employee has a unique ID.
b) Foreign Key
- Maintains relationships between tables by linking to a primary key.
- Maintains relationships between tables by linking a column to a primary key in another table.
c) NOT NULL
- Ensures a column cannot contain NULL values, forcing essential fields to always have data.
- For example, each user should have a unique username, even if they share the same name.
d) UNIQUE
- Ensures all values in a column are distinct (no duplicates).
e) CHECK
- Restricts values based on specific conditions to ensure data validity.
- An employee's age must be 18 or older.
f) DEFAULT
- Assigns a default value if no value is provided.
- New orders should automatically be set to "Pending" unless specified otherwise.
Importance of constraints:
Maintain data integrity (correctness of data)
Prevent errors and duplication
Ensure consistency in relationships
1.2 Examples of Databases
a) Relational Databases
- Relational databases store data in tables and use relationships between tables. They use
SQL for to query and manage data.
Examples:
MySQL: An open-source relational database widely used in web
applications.
PostgreSQL: A powerful open-source relational database known for its
advanced features and extensibility.
Oracle Database: A commercial relational database system with robust
features for enterprise applications.
Microsoft SQL Server: A relational database management system
developed by Microsoft, used in various business applications.
b) NoSQL Databases
- NoSQL databases are designed for handling unstructured or semi-structured data and can
accommodate a variety of data models such as key-value, document, column-family, or
graph.
Examples:
MongoDB: A document-oriented NoSQL database that stores data in
JSON-like documents.
Redis: A key-value store known for its speed and used for caching and
real-time data processing.
Cassandra: A column-family NoSQL database designed for high
availability and scalability.
Neo4j: A graph database used for handling complex relationships and
interconnected data.
c) In-Memory Databases
o In-memory databases store data in the system’s main memory (RAM) rather than
on disk, providing extremely fast data access.
Examples:
Memcached: An in-memory key-value store used for caching database
queries and improving performance.
Redis: Also used as an in-memory database for its high-speed data
operations.
d) Object-Oriented Databases
- Object-oriented databases store data in the form of objects, similar to how data is
represented in object-oriented programming.
Examples:
ObjectDB: An object-oriented database for Java applications.
db4o: An open-source object database that supports Java and .NET
applications.
e) Cloud Databases
- Cloud databases are hosted and managed in the cloud, providing scalable and flexible
data storage solutions.
Examples:
Amazon RDS: A managed relational database service that supports
various DBMSs like MySQL, PostgreSQL, and Oracle.
Google Cloud SQL: A fully-managed relational database service on
Google Cloud Platform.
Azure Cosmos DB: A globally distributed, multi-model database service
by Microsoft Azure that supports NoSQL data models.
Examples:
Moodle – A popular open-source LMS used by schools, universities, and businesses for
online learning.
Blackboard Learn – A widely used LMS in higher education with robust course
management tools.
Google Classroom – A free LMS by Google, often used in K-12 education.
Canvas LMS – A modern and scalable LMS used by universities and corporations.
TalentLMS – A cloud-based training platform for businesses offering employee training.
Example: A retail company uses sales data analysis to determine customer buying patterns and
adjust stock levels.
Example: A cashier at a supermarket uses a POS system to process sales, retrieving product
prices from a database.
Example: A data engineer processes millions of customer transactions and loads them into a
business intelligence dashboard.
In conclusion:
Each database role plays a crucial part in ensuring a secure, efficient, and well-managed database
system. From designing and maintaining the database to analyzing and securing data, these roles
contribute to smooth business operations.