UH2C - ENSEM - GE
Database Course for
Electrical Engineering
Nassim Bout, MRes | December 17, 2023
Agenda
• General overview
• What is a Database?
• Importance of Databases
• Database Management Systems (DBMS)
• Types of DBMS
• Introduction to RDBMS
• Key Features and Advantages of RDBMS
• Entities, Relationships, and ACID Properties
• Examples of Popular RDBMS
• Comparing RDBMS
General overview
Session 1 Session 2
• Introduction to Databases Management • Relational Database Management Systems
Systems (DBMS). (RDBMS).
• Conceptual Data Model (CDM) and Logical
Data Modeling.
Session 3 Session 4
• Querying a Database and Advanced SQL. • Practical Exercise.
• Modifying Data and Project Introduction. • Review and Q&A.
What is a Database?
Key Points
● Definition of a database and its purpose
● Brief explanation of the importance of databases in
electrical engineering
● Relevance of databases to the field of electrical
engineering
A Databases
• Organized and structured collection of
data.
• Managed, accessed and uploaded.
• Centralized repository for storing,
organizing and retrieving information.
• Facilitates manipulation and analysis
data.
Speaking history
• From traditional data structures (stacks and queues) to modern databases
equal a increasing complexity and volume of data.
• 1960s : CODASYL database model.
• 1970s : Edgar F. Codd's relational model.
• 21st century : NoSQL databases emerged, and Cloud-based databases.
Key Components of a Database & its Purpose
-> Tables, relationships, and queries.
-> Data integrity, security, and ease of retrieval
Example in Everyday Life
Address book are like
mini-databases.
Importance of Databases in Electrical Engineering
-> Data Management in Electrical Engineering
-> Efficient Storage and Retrieval
-> Collaboration and Concurrent Access
Relevance of Databases to Electrical Engineering
-> Integration of IoT and Big Data
-> Smart Grids and Energy Management
-> Research and Development
-> Future Trends
Importance of Databases
Databases store vast amounts of electrical engineering data, from circuit
designs to power distribution records.
Efficient data retrieval and management are critical for electrical engineers
working on complex projects.
Databases provide a secure and structured way to store, manage, and access
engineering data.
Database Management Systems (DBMS)
Database Management System (DBMS) is a systematic and structured software application
that facilitates the creation, organization, retrieval, and management of data within a digital
environment. It serves as a foundational component in information systems, offering a
standardized and efficient mechanism for users and applications to interact with data.
Components of DBMS
Five fundamental components that make up a Database Management System (DBMS)
• Hardware • Procedures
• Software • Data
• Database Access Language
Types of DBMS
Hierarchical, Network, Relational, Object-oriented
Graph, Document, Wide-column, Key-value
OLTP - Online Transaction Processing, OLAP - Online Analytical Processing
Centralized, Distributed, Personal, Parallel, Real-time
Types of DBMS
Hierarchical, Network, Relational, Object-oriented
• Usage Distribution:
○ Relational: 70%
Categorized based on the underlying data ○ Hierarchical: 10%
model. ○ Network: 8%
○ Object-oriented: 12%
• Hierarchical and Network: These are early
data models that organize data in tree-like • Common Applications:
or network structures. ○ Relational: Business applications, financial
• Relational: Organizes data in tables with systems.
○ Hierarchical: Legacy systems, file
rows and columns.
management.
• Object-oriented: Treats data as objects
○ Network: Library systems, data management
with encapsulated data and methods.
in scientific research.
○ Object-oriented: Multimedia databases, CAD
systems.
Types of DBMS
Graph, Document, Wide-column, Key-value
Categorized based on newer database models • Usage Distribution:
and structures. ○ Document: 40%
○ Graph: 30%
• Graph: Represents data as nodes and ○ Wide-column: 15%
edges, suitable for complex relationships. ○ Key-value: 15%
• Document: Stores data in flexible,
JSON-like documents. • Common Applications:
• Wide-column: Optimized for storing and ○ Document: Content management,
retrieving large amounts of data. real-time collaboration.
• Key-value: Stores data as key-value pairs, ○ Graph: Social networks, fraud detection.
suitable for simple data storage and ○ Wide-column: Time-series data, sensor
data.
retrieval.
○ Key-value: Caching, session storage.
Types of DBMS
OLTP - Online Transaction Processing, OLAP - Online Analytical Processing
• Usage Distribution:
Categorized based on the types of processing
○ OLTP: 60%
tasks the databases are optimized for.
○ OLAP: 40%
• OLTP: Optimized for handling transactional
• Common Applications:
operations in real-time, like online banking.
○ OLTP: Retail transactions, online banking.
• OLAP: Optimized for analytical processing,
○ OLAP: Business intelligence, data
supporting complex queries and reporting.
warehousing.
Types of DBMS
Centralized, Distributed, Personal, Parallel, Real-time
Categorized based on the deployment and • Usage Distribution:
processing characteristics. ○ Distributed: 45%
○ Centralized: 25%
• Centralized: A single database system ○ Parallel: 15%
manages data. ○ Real-time: 10%
• Distributed: Data is distributed across ○ Personal: 5%
multiple locations or servers. • Common Applications:
○ Distributed: Cloud databases, global applications.
• Personal: Designed for individual use or
○ Centralized: Small business applications, standalone
small-scale applications. systems.
• Parallel: Processes data simultaneously ○ Parallel: High-performance computing, large-scale
using multiple processors. data processing.
• Real-time: Handles data with minimal ○ Real-time: Financial systems, monitoring and control.
○ Personal: Small-scale applications for individual use.
delay for time-sensitive applications.
UH2C - ENSEM - GE
Relational DataBase
Management Systems
Nassim Bout, MRes | December 17, 2023
Introduction to RDBMS
What is an RDBMS and Why are RDBMS so What are the specific
how does it differ from widely used in the features of RDBMS that
other types of DBMS? industry? make them suitable for
managing complex data?
Data is structured into Reliable
tables, each consisting of Structured Organization
Structured
rows and columns. The Data Integrity and
relationships between Standardized Querying
tables are established
-> Data Management Transaction Management
through keys
Approach and Scalability
Key Features and Advantages of RDBMS
1 Unique key constraints 4 Built-in security measures to
ensure data integrity. protect sensitive information.
Advantages in data
Support for complex queries organization and efficiency
2 and multi-table transactions.
5 compared to non-relational
databases.
Scalability to handle large Compatibility with SQL, a
3 datasets and simultaneous 6 widely adopted standard for
users. data management.
Entities, Relationships, and ACID Properties
What are Entities?
Entities in RDBMS represent a person, place, thing, or event about which data can
be stored. In the context of electrical engineering, this could be a specific
component or system.
Entities:
○ Device:
■ Attributes: DeviceID (Primary Key), DeviceName, DeviceType,
PowerRating
○ Room:
■ Attributes: RoomID (Primary Key), RoomName
○ User:
■ Attributes: UserID (Primary Key), UserName, UserEmail
Entities, Relationships, and ACID Properties
Understanding Relationships
In terms of electrical engineering, relationships in RDBMS define how entities are
connected. This can be related to the interactions between different components
or elements in a system.
Relationships:
○ InstalledIn (Relationship between Device and Room):
■ Description: A device is installed in a room.
■ Foreign Key: RoomID (in Device)
○ UsedBy (Relationship between Device and User):
■ Description: A user uses a device.
■ Foreign Key: UserID (in Device)
Entities, Relationships, and ACID Properties
The Importance of ACID Properties
ACID properties are essential in maintaining the integrity of data in RDBMS. This is
crucial in scenarios where electrical systems rely on precise and consistent data.
Entities, Relationships, and ACID Properties
Implications for Electrical Engineering
The concepts of entities, relationships, and ACID properties are directly applicable
to the design and management of data in electrical engineering systems.
Smart Grid System :
Entities: could include devices like smart meters, renewable energy sources (solar
panels, wind turbines), electrical substations, and consumer households.
Relationships: Could represent connections and interactions between entities. For
instance, the relationship between a smart meter and a household, or the
relationship between renewable energy sources and the electrical grid.
Examples of Popular RDBMS
MySQL is used in various applications such as data
MySQL
warehousing, e-commerce, and logging applications.
PostgreSQL is known for its strong compliance to
PostgreSQL
standards, extensibility, and advanced features.
Oracle Database is widely used in enterprise applications,
Oracle DB
known for its scalability, security, and reliability.
Comparing RDBMS
➔ MySQL is an open-source relational database management system (RDBMS) known for its simplicity,
speed, and reliability. It is commonly used in web applications and content management systems.
MySQL is suitable for projects with high read and write requirements, making it popular for
e-commerce platforms, blogs, and various online applications. Its usage distribution is extensive,
with MySQL accounting for around 20% of all databases, making it one of the most widely used
databases globally.
➔ PostgreSQL is another open-source RDBMS renowned for its advanced features, extensibility, and
support for complex queries. It excels in handling large datasets and is often chosen for
applications that require complex data relationships, such as geographical information systems
(GIS) and data warehousing. PostgreSQL's usage distribution has been growing steadily, and it
currently holds around 10% of the database market share.
➔ Oracle Database, developed by Oracle Corporation, is a powerful, commercial RDBMS widely used in
enterprise settings for mission-critical applications. It offers advanced features like partitioning,
clustering, and high availability, making it suitable for large-scale business applications, financial
systems, and telecommunications. Oracle Database has a significant presence in the enterprise
sector, holding approximately 40% of the database market share.
UH2C - ENSEM - GE
Data Modeling
Nassim Bout, MRes | December 17, 2023
Data modeling?
Database Modeling: An Overview
Database modeling is the process of creating abstract representations of a
database's structure and interactions. It involves defining entities, relationships,
and attributes to capture the organization and flow of data within a system.
Data modeling?
Why Database Modeling Matters?
Key Points:
• Structured Information: "Database modeling brings structure to information,
making it organized and easy to manage."
• Data Integrity: "Ensures data accuracy and integrity by defining relationships
and constraints."
• Efficient Queries: "Optimizes data retrieval and query performance."
• Future Planning: "Facilitates scalability and adaptability for future changes in
data requirements."
Steps of modeling data
The ERD : Entity-Relationship Diagram
Understanding ERD
The Entity-Relationship Diagram (ERD) is a visual representation of the entities,
relationships, and attributes within a database system. It serves as a blueprint for
designing databases, illustrating how data entities are interconnected and how
they relate to one another.
ERD (Entity-Relationship-Diagram) is one of the method in Conceptual Data
Modeling in order to flesh out in visual form the user requirements whether explicit
or implicit in nature.
The ERD : Entity-Relationship Diagram
Key Components of ERD
• Components:
• Entities: "Represent real-world objects, such as customers, products, or
employees."
• Relationships: "Illustrate how entities are connected or associated with each
other."
• Attributes: "Characteristics or properties that describe entities and
relationships."
• Primary Key: "An attribute or combination of attributes that uniquely identifies
each instance of an entity."
Data Dictionary and Normalization Concepts
Data Dictionary: Unlocking Database Insights
A Data Dictionary is a centralized repository that provides a detailed description of
data elements within a database. It serves as a comprehensive reference guide,
capturing metadata, attributes, and relationships to enhance understanding and
management of data.
Data Dictionary and Normalization Concepts
Why Data Dictionary Matters
Key Points:
• Consistency: "Ensures consistent usage and interpretation of data across the
organization."
• Collaboration: "Facilitates collaboration among team members, fostering a
shared understanding of data."
• Documentation: "Serves as living documentation, aiding in system
maintenance and updates."
• Quality Control: "Enhances data quality by enforcing standards and
guidelines."
Data Dictionary and Normalization Concepts
Data Normalization: Structuring for Efficiency
Data normalization is a database design technique that organizes tables and
minimizes data redundancy. It aims to reduce anomalies and improve data integrity
by systematically applying rules to eliminate redundant and duplicated information.
Data Dictionary and Normalization Concepts
Key Concepts of Data Normalization
Concepts:
• First Normal Form (1NF): "Ensures atomicity by eliminating repeating groups
and ensuring each field contains only one piece of information."
• Second Normal Form (2NF): "Builds on 1NF by addressing partial
dependencies, ensuring all non-key attributes are fully functionally dependent
on the primary key."
• Third Normal Form (3NF): "Further refines the structure by removing
transitive dependencies, ensuring non-key attributes depend only on the
primary key."
Data Dictionary and Normalization Concepts
Why Data Normalization Matters
Key Points:
• Reduces Redundancy: "Minimizes data duplication, leading to more efficient
storage."
• Improves Integrity: "Enhances data accuracy and consistency by eliminating
anomalies."
• Facilitates Maintenance: "Simplifies updates and modifications to the
database structure."
• Optimizes Performance: "Leads to better query performance and overall
system efficiency."
Overview of Conceptual Data Model (CDM)
Definition
A Conceptual Data Model (CDM) is a high-level representation of an organization's
data from a business perspective. It focuses on capturing essential entities, their
relationships, and key attributes, providing a foundational understanding of the
data structure without delving into technical details.
Overview of Conceptual Data Model (CDM)
CDM vs ERD: Understanding the Contrast
While both the Conceptual Data Model (CDM) and Entity-Relationship Diagram
(ERD) serve as tools for visualizing database structures, they differ in their focus,
level of detail, and intended audience.
Overview of Conceptual Data Model (CDM)
Key Differences: CDM vs ERD
Differences:
• Level of Detail: "CDM focuses on high-level business concepts, omitting
technical details. ERD delves into technical specifics, including attributes and
keys."
• Intended Audience: "CDM is designed for business stakeholders to
understand data from a business perspective. ERD targets database
designers and developers, providing a blueprint for implementation."
• Scope: "CDM sets the scope by defining essential business elements. ERD
goes deeper into the specifics of entities, attributes, and relationships."
Overview of Conceptual Data Model (CDM)
Choosing Between CDM and ERD
Considerations:
• Project Phase: "CDM is ideal for initial project discussions and scoping. ERD
comes into play during detailed database design and implementation phases."
• Stakeholder Engagement: "Use CDM when communicating with business
stakeholders. Shift to ERD when engaging with the technical team."
• Balance: "A well-balanced project often involves starting with a CDM for
alignment and transitioning to an ERD for detailed implementation."
Transition from CDM to Logical Data Model (LDM)
The LMD
The transition from a Conceptual Data Model (CDM) to a Logical Data Model (LDM)
involves refining and detailing the high-level concepts from the CDM into a
structure that can be implemented in a specific database management system
(DBMS).
Transition to LDM
1. Refining Entities and Attributes:
• CDM: Entities and attributes are presented at a high level, focusing on
business concepts.
• LDM: Refine entities by specifying attributes more precisely. Define data
types, lengths, and constraints for each attribute based on the chosen DBMS.
2. Identifying Primary and Foreign Keys:
• CDM: Primary keys are identified at a conceptual level without delving into
specific implementation details.
• LDM: Specify primary keys for each entity. Identify foreign keys based on
relationships with other entities.
Transition to LDM
3. Defining Relationships and Cardinalities:
• CDM: Relationships are presented at a conceptual level, emphasizing
associations between entities.
• LDM: Define relationship types (one-to-one, one-to-many, many-to-many)
and cardinalities. Ensure that foreign keys are correctly identified to establish
referential integrity.
4. Normalizing Data:
• CDM: Normalization concepts may be discussed at a high level in the CDM.
• LDM: Apply normalization rules to organize data efficiently. Decompose
entities to eliminate redundancy and improve data integrity.
Transition to LDM
5. Choosing Data Types:
• CDM: Data types may be generic or not specified in the CDM.
• LDM: Select appropriate data types for each attribute based on the specific
requirements of the DBMS (e.g., VARCHAR, INT, DATE).
6. Handling Business Rules:
• CDM: Business rules are discussed conceptually.
• LDM: Ensure that business rules are accommodated in the logical model. For
example, if a certain constraint is crucial for business logic, it needs to be
translated into appropriate constraints in the logical model.
Transition to LDM
7. Ensuring Integrity Constraints:
• CDM: Integrity constraints are considered but not explicitly defined.
• LDM: Specify integrity constraints such as unique constraints, check
constraints, and defaults based on the requirements of the DBMS.
8. Considering Performance and Indexing:
• CDM: Performance considerations are not the primary focus.
• LDM: Introduce considerations for indexing, taking into account query
performance and database optimization.
Transition to LDM
9. Aligning with DBMS Specifics:
• LDM: Consider specific features and requirements of the chosen DBMS.
Different DBMS may have unique syntax or constraints.
10. Documentation:
• LDM: Documentation becomes more detailed. Provide clear explanations for
each element in the model, including constraints, relationships, and data
types.
ERD, CDM, LDM
Conceptual Data Model (CDM) - Merise Notation
ERD, CDM, LDM
Logical Data Model (LDM) - Relational Notation
ERD, CDM, LDM
Conceptual Data Model (CDM) - Hybrid (Adapted) Notation
UH2C - ENSEM - GE
Structured Query
Language - SQL
Nassim Bout, MRes | December 17, 2023
SQL?
SQL in Brief: Structured Query Language (SQL) is a standardized programming
language designed for managing and manipulating relational databases. SQL provides a
set of commands for defining, querying, and maintaining databases. It enables users to
interact with databases by performing operations such as retrieving data, inserting new
records, updating existing records, and deleting data. SQL is fundamental to relational
database management systems (RDBMS) and is widely used for database-related tasks
across various industries.
Founding Year: SQL was conceived in the early 1970s. Its development can be traced
back to the research work of Donald D. Chamberlin and Raymond F. Boyce at IBM. The
initial version of SQL, called SEQUEL (Structured English Query Language), was
developed in the mid-1970s as part of an IBM project for managing databases. The first
official SQL standard, SQL-86, was established in 1986 by the American National
Standards Institute (ANSI). Since then, SQL has undergone several revisions, with ANSI
and the International Organization for Standardization (ISO) maintaining and updating
the standards periodically.
What can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create stored procedures in a database
• SQL can create views in a database
• SQL can set permissions on tables, procedures, and views
For web?
• An RDBMS database program (i.e. SQLite, SQL Server, MySQL)
• To use a server-side scripting language, like Python, PHP, ASP, or Node.JS
• To use SQL to get the data you want
• To use HTML / CSS to style the page
Creating a Database using SQL
SQL command for creating a database
-- Create the database
CREATE DATABASE IF NOT EXISTS SmartHouseSystem;
-- Use the database
USE SmartHouseSystem;
-- Table for Owners
CREATE TABLE IF NOT EXISTS Owners (
OwnerID INT PRIMARY KEY,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Email VARCHAR(100) UNIQUE NOT NULL,
Phone VARCHAR(15)
);
Writing and Executing SELECT Statements
Syntax of SELECT statements with examples
-- Retrieve an owner’s full name and email
SELECT FirstName, LastName, Email FROM Owners;
-- Get all information about owners
SELECT * FROM Owners;
Filtering and Sorting Data
WHERE clause for filtering & ORDER BY clause for sorting
-- Retrieve owners whose ‘LastName’ is 'Smith'
SELECT * FROM Owners WHERE LastName = 'Smith';
-- Retrieve all owners, ordered by their ‘FirstName’ in ascending order
SELECT * FROM Owners ORDER BY FirstName ASC;
Joins
Inner and Outer joins
Joins
INNER JOIN & LEFT JOIN
-- Retrieves rows where there is a match in both tables
SELECT Owners.FirstName, Owners.LastName, Rooms.RoomName
FROM Owners
INNER JOIN Rooms ON Owners.OwnerID = Rooms.OwnerID;
-- Retrieves all rows from the left table and matched rows from the
right table. If there is no match in the right table, NULL values are
returned
SELECT Owners.FirstName, Owners.LastName, Rooms.RoomName
FROM Owners
LEFT JOIN Rooms ON Owners.OwnerID = Rooms.OwnerID;
Joins
RIGHT JOIN & FULL JOIN
-- Retrieves all rows from the right table and matched rows from the
left table. If there is no match in the left table, NULL values are
returned.
SELECT Owners.FirstName, Owners.LastName, Rooms.RoomName
FROM Owners
RIGHT JOIN Rooms ON Owners.OwnerID = Rooms.OwnerID;
-- Retrieves all rows when there is a match in either the left or right
table. It returns NULL values for unmatched rows.
SELECT Owners.FirstName, Owners.LastName, Rooms.RoomName
FROM Owners
FULL JOIN Rooms ON Owners.OwnerID = Rooms.OwnerID;
Aggregate Functions
Overview of aggregate functions (SUM, AVG, COUNT, etc.)
-- Retrieve the minimum and maximum values for the readings
SELECT MIN(Value) AS MinReading, MAX(Value) AS MaxReading FROM
DeviceReadings;
-- Calculate the average value of the readings
SELECT AVG(Value) AS AverageReading FROM DeviceReadings;
-- Count the number of readings
SELECT COUNT(*) AS ReadingCount FROM DeviceReadings;
-- Use a wildcard to search for readings
SELECT * FROM DeviceReadings WHERE ReadingType LIKE 'Temper%';
INSERT, UPDATE, and DELETE Statements
Syntax and examples
-- Add a new owner to the ‘Owners’ table
INSERT INTO Owners (OwnerID, FirstName, LastName, Email, Phone)
VALUES (1, 'John', 'Doe', '
[email protected]', '123-456-7890');
-- Update the email address for a specific owner
UPDATE Owners
SET Email = '
[email protected]'
WHERE OwnerID = 1;
-- Delete an owner from the ‘Owners’ table
DELETE FROM Owners
WHERE OwnerID = 1;
Transactions and Data Integrity
Transactions represent a logical unit of work composed of one or more SQL
statements. These statements can include operations like INSERT, UPDATE,
DELETE, and SELECT. The primary objective of transactions is to ensure that a
series of database operations either succeed as a whole or fail entirely.
Transactions adhere to the principles of Atomicity, Consistency, Isolation, and
Durability, collectively known as the ACID properties.
Transactions and data integrity are intertwined concepts in database
management. Through the application of ACID properties and the grouping of SQL
statements within transactions, databases maintain a high level of reliability,
consistency, and accuracy, ensuring that data remains a trustworthy foundation
for decision-making and analysis.