SlideShare a Scribd company logo
1 of 31
Download to read offline
1
Database Systems
Introduction to the Structured Query
Language
Harmony Kwawu
hkwawu@aol.com
Course Outline
Introduction
Use of database applications
Database Management System
Relational operators
Purpose of relational database query
SQL Commands:
Data manipulation command
Data definition command
SQL Joins
Summary
3
Introduction
Our world depends on data and increasingly so, in order to thrive.
There are many different methods used for storing data but the idea
of relational database technology has proved the most advantageous
A key benefit of relational database approach is the capacity to allow
users to retrieve data from or interact with database in an intuitive
and variant ways.
At the heart of all major relational database approach is the SQL,
standing for Structured Query Language. SQL is based on set theory
or relational principles.
Relational operators help developers write complex procedures to
enforce business rules and enhance database interactivity
There are six different types of relational operators used in major
DBMS as illustrated in this brief introduction to the Structured Query
Language
But first ….
Uses of Database Applications
24/01/2011 ©HKwawu 5
Uses of Database Applications
• Databases are the backbone of all
information systems. Examples of
information system types include:
• Patient appointment systems
• Library customer registration and
account management systems
• Automatic Teller Machine (ATM)
• Hotel reservation and bookings
systems
• Stock control systems, and
• School information mgt systems (SIMS)
Relational Database Systems
Relational Database Systems
There are different ways to store data. Data can be stored in
files, documents, image and sound forms etc
But relational database approach is the most versatile and
convenient
Relational database approach is one in which data is
organised into sets or tables
Where each table is linked to other tables to form a relational
model.
STUDENT
Student_ID (PK)
StudentName
StudentAddress
Email
Telephone
Comment
Course_Code(FK)
ModuleModule
Module_Id(PK)
Module Name
Aim
Outcome
Course_Code (FK)
Course_Code(PK)
CourseName
CourseDescription
CourseCourse
A simple illustrated example of relational data model.
Relations
Tables in a relational database are technically
referred to as entities or relations.
Key Components
The main components of relational database systems are:
The database or data repository consisting of:
Individual tables linked to form a logical model
Attributes of stored data
Specific values or records
Database Manager (BM)
The command base for retrieving and managing the
database (SQL)
Applications for interacting with the content of the data
base
User interface
Major benefits of Relational database systems
Relational database approach also
allow data from different parts of
an organisation to be stored in
one place
This approach makes it easy to
protect and control access to the
database
Also, storing data in a logically
related tables can be accessed by
different applications and users
according to their needs
SQL
What is Database Management System
13
Database Management System (DBMS)
A database management system (DBMS) is a large piece of
software that is used in defining, creating, updating and
deleting a database records.
A database management system is also known as database
manager
It supports the operation of database applications within an
integrated, controlled and accessible framework.
Examples of DBMS are:
MS Access
Oracle PL/SQL
MySQL
13
A simple Infographics of Database
Management Systems
Data Base Query
Relational Database Operators
Operators are generally used in programming and application
development to build expressions.
There are generally four categories of operators, namely:
Arithmetic operators
Relational or Boolean Operators
Logical Operator
Assignment Operator
Relational operators are the most common type of operators
used in relational database
They are used to help write complex procedures to enforce
business rules and construct query statements
Data Base Query
Database Relational Operators
Common Database Relational Operators
OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning ExampleExampleExampleExample
= Equal to Gives exact value in a database
<> Not equal to List values other than the one
specified
> Greater than List values that are greater
than the one specified
< Less than Shows values that are less
than the one stated
<= Less than or equal to Shows values stated and all
values less than the one stated
>= Greater than or equal to Shows values specified and all
values greater than the one
stated
Other Database Relational Operators
Cont..
OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning ExampleExampleExampleExample
Between ......> And <..... Retrieve all values within the
given range excluding the two
values stated
Between Between Retrieve all values within the
given range including the two
values stated
OR ......OR ...... List one set of value or
another
The SQL Command
21
The SQL command
We shall examine in future posts how the above operators are
used to programme relational database,
But first let’s discuss other aspect of database query-the SQL
command.
As noted above, SQL allow database users to retrieve data,
update existing records, delete records, create index, create
new tables and delete tables
SQL statements can be interactive and embedded in third
party programming languages, such as ASP.NET or PHP
And SQL statement may be simple or complex, more on this in
future
22
SQL Command
In MS Access database management systems for example,
queries are created using what is known as Access Query
Design view.
The queries created in design view can be viewed and edited
to reflect changes
It’s equally possible to write new query statements directly in
SQL view
Note that SQL Stand for structured query language and that
SQL is the defector programming language for relational
databases.
23
Illustrated Example: Query Design View
A very simple query
A local bank require the design of a system to store record of its clients
and the loan they borrow. The system should be able to store details of
the clients, details of loan and loan types and the branch for Each
customer. A preliminary entity relation model has been produced by one
of your database development team member as shown below: use the
ERD to produce the following queries
Bank customer loan processing system challenge
25
Illustrated Example: Query Design View
Bank Database
Model
A slightly complex query
SQL View in MS Access
SQL Query statement
SQL Command Types
28
SQL Command Types
There are many categories of structured Query Language
statements.
For our purpose, we shall focus on two key categories as
follows:
The data definition language (DDL) commands, and
Data manipulation language (DML) commands
DDL and DML
Data Definition Language (DDL)
Are used to define and model the structure of data
e.g. Create the database, Alter (make changes to the
database) and Drop (delete database object)
Data Manipulation Language (DML)
Used mainly for interacting and manipulating stored data
e.g. Select, Update, Delete and Insert new records into
database
Data Definition Language (DDL)
Create statement
Alter statement, and
Drop statement
31
Example 1: SQL Create Table Command
Create Table Staff(
Staff_Id Number (10) NOT Null Staff_FirstName Varchar(30)
NOT Null,
Staff_SurName Varchar(30) NOT Null,
Staff_Position Varchar(10) NOT Null,
Staff_EmailVarchar(30) NOT Null,
Staff_Telephone Varchar(30) NOT Null,
Room_Number Varchar(30) NOT Null,
Staff_Speciality Varchar(30) NOT Null,
Constraints Staff_PK Primary Key (Staff_id));
The Result
See if you can guess the result by sketching it
33
Example2: SQL Create Table Cont..
Create Table Course (
Course_Code Number (10) NOT Null,
Course_Name Varchar(30) NOT Null,
Course_Aim Varchar(30) NOT Null,
Course_Description Varchar(100) NOT Null,
Staff_Id Number (30),
Constraints Course_PK Primary Key (Course_Code),
CONSTRAINTS Staff_FK FOREIGN (Staff_Id),
REFERENCES Staff(Staff));
The Result
Again, see if you can guess the result by
sketching it
Other important DDL Statements
Other important DDL Statements
Alter statement and Drop statement
Find out more from the link below:
http://www.w3schools.com/sql/sql_alter.asp
Data Manipulating Language
Data Manipulating Language
Select statement is perhaps the most important and
frequently used data manipulation statement.
Other equally important commands are:
Update command
Delete command
Insert command
The main purpose of DML, is to allow database users to
retrieve (select) and or manipulate stored data
Structure of select statement
Below are what could be descried as the building blocks of
simple select command:
SELECT
FROM
Where
Or
Quiz
Briefly describe what Each of the following select statement
keywords means in practice?
SELECT
FROM
Where
Or
Example of select statement:
List the names and email address of all staff
in room 123
SELECT (Staff_ID, First Name, Surname,
Email, Telephone, Room
FROM Staff,
WHERE ((Room)=123));
The Result
See if you can guess the result by sketching it
43
Data Manipulating Language
Example of DML select statement-2:
List Name and detail of students
SELECT Student_ID, First_Name, Surname,
Email, Mobile, Home_Tel
FROM Student;
The Result
See if you can guess the result by sketching it
45
DML SQL Command
List names of students and their course
SELECT Student_ID, First_Name, Surname, D_O_B,
Email,Course_Name, Description
FROM Course INNER JOIN Student ON
tblCourse.Course_ID=TblStudent.Course_ID;
The Result
Congratulation if you were able to guess
the result correctly by sketching it
47
Other Types of DML Query
Update Query in MS Access:
Example 1:
UPDATE TblStudent SET TblStudent.First_Name = "Null",
TblStudent.Surname = “Null”, TblStudent.D_O_B = “Null”;
Example 2:
UPDATE TblJob_Type SET TblJob_Type.Charges = “£90";
Log on to the URL below to find out more:
http://www.w3schools.com/sql/sql_update.asp
49
Delete Query in MS Access
Delete all record from the Module Table
DELETE *
FROM TblModules;
50
Insert data into table
INSERT INTO Student
(Student_Name,Student_Address,Email)
Values (Joe Williams, London Road, JW@Yahoo.com);
INSERT INTO Student
(Student_Name,Student_Address,Email)
Values (Henry Champion, West Kent Road,
HC@Yahoo.com);
INSERT INTO Student
(Student_Name,Student_Address,Email) Values (Mark
Williams, China Town, MW@Yahoo.com);
51
Project Report 1
52
SQL Report1
SELECT Projects_Tbl.Project_Id,Projects_Tbl.Project_Name,
Employees_Tbl.Employee_No,Employees_Tbl.Employee_Na
me, Job_Type_Tbl.Job_Class, Job_Type_Tbl.Charges,
Employee_Project_Tbl.Hours
FROM (Projects_Tbl INNER JOIN (Employees_Tbl INNER
JOIN Employee_Project_Tbl ON
Employees_Tbl.Employee_No=Employee_Project_Tbl.Emply
ee_Number) ON
Projects_Tbl.Project_Id=Employee_Project_Tbl.Project_id)
INNER JOIN Job_Type_Tbl ON
Projects_Tbl.Project_Id=Job_Type_Tbl.Project_Id;
Output report
Try and sketch what you think the output is likely
to be
54
Project Report 2
Fig: Select Query to generate the report below
Fig: Result of the query
55
SQL Report 2
SELECT Projects_Tbl.Project_Id,
Projects_Tbl.Project_Name, Employees_Tbl.Employee_No,
Employees_Tbl.Employee_Name, Job_Type_Tbl.Job_Class,
Job_Type_Tbl.Charges, Employee_Project_Tbl.Hours,
[Charges]*[hours] AS Total
FROM (Projects_Tbl INNER JOIN (Employees_Tbl INNER
JOIN Employee_Project_Tbl ON
Employees_Tbl.Employee_No =
Employee_Project_Tbl.Emplyee_Number) ON
Projects_Tbl.Project_Id = Employee_Project_Tbl.Project_id)
INNER JOIN Job_Type_Tbl ON Projects_Tbl.Project_Id =
Job_Type_Tbl.Project_Id;
56
Write SQL Query to implement the following two Tables. You
may use MS Access Query design to help you complete this
task. The tables are based on the Project/Employee database
Table: 1
Table: 2
Try this revision task
57
Joins Statements
SQL join commands are useful when querying data from
multiple tables that are linked together
58
Joins Statements Cont’..
Types of joins:
INNER JOIN (JOIN): Return rows when there is at least one match
in both tables
LEFT JOIN: Return all rows from the left table, even if there are no
matches in the right table
RIGHT JOIN: Return all rows from the right table, even if there are
no matches in the left table
FULL JOIN: Return rows when there is a match in one of the tables
See the sites below for further details on joins:
http://infogoal.com/sql/sql-outer-join.htm
http://www.w3schools.com/sql/sql_join_inner.asp
59
Summary
In this post, we’ve learnt that SQL is a command based language
which allow database developers to create and manipulate stored
record
SQL can be used to create the database, make changes to the
database and delete database objects
SQL also help users to interact and manipulate stored data.
Users can make a request (declare) for the data they require without
the need to specify how the request should be processed
SQL is a powerful language to learn as it is the most popular
programming language for relational database applications
Next Post
Advance SQL
Additional SQL online tutorials you!
Introduction to SQL:
http://www.w3schools.com/sql/sql_intro.asp
End
Feel free to get in touch if you
would like to share your
thought on this topic. You can
contact me by email at:
hkwawu@aol.com

More Related Content

What's hot

SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
Smriti Jain
 

What's hot (20)

Sql commands
Sql commandsSql commands
Sql commands
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
SQL
SQLSQL
SQL
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
SQL
SQLSQL
SQL
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
 
Sql commands
Sql commandsSql commands
Sql commands
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commands
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 

Similar to Introduction to the Structured Query Language SQL

Bank mangement system
Bank mangement systemBank mangement system
Bank mangement system
FaisalGhffar
 
Lecture on DBMS & MySQL.pdf v. C. .
Lecture on DBMS & MySQL.pdf v.  C.     .Lecture on DBMS & MySQL.pdf v.  C.     .
Lecture on DBMS & MySQL.pdf v. C. .
MayankSinghRawat6
 
Module02
Module02Module02
Module02
Sridhar P
 
Introduction to sql server
Introduction to sql serverIntroduction to sql server
Introduction to sql server
Vinay Thota
 
Sql server
Sql serverSql server
Sql server
Puja Gupta
 

Similar to Introduction to the Structured Query Language SQL (20)

Bank mangement system
Bank mangement systemBank mangement system
Bank mangement system
 
Lecture on DBMS & MySQL.pdf v. C. .
Lecture on DBMS & MySQL.pdf v.  C.     .Lecture on DBMS & MySQL.pdf v.  C.     .
Lecture on DBMS & MySQL.pdf v. C. .
 
Module02
Module02Module02
Module02
 
Data base
Data baseData base
Data base
 
sql ppt.pptx
sql ppt.pptxsql ppt.pptx
sql ppt.pptx
 
Introduction to sql server
Introduction to sql serverIntroduction to sql server
Introduction to sql server
 
Chapter02
Chapter02Chapter02
Chapter02
 
Sql server
Sql serverSql server
Sql server
 
Lecture 1 to 3intro to normalization in database
Lecture 1 to 3intro to  normalization in databaseLecture 1 to 3intro to  normalization in database
Lecture 1 to 3intro to normalization in database
 
Chapter Five Physical Database Design.pptx
Chapter Five Physical Database Design.pptxChapter Five Physical Database Design.pptx
Chapter Five Physical Database Design.pptx
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Introduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQLIntroduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQL
 
Mca ii-dbms- u-ii-the relational database model
Mca ii-dbms- u-ii-the relational database modelMca ii-dbms- u-ii-the relational database model
Mca ii-dbms- u-ii-the relational database model
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
Bsc cs ii-dbms- u-ii-database system concepts and architecture
Bsc cs ii-dbms- u-ii-database system concepts and architectureBsc cs ii-dbms- u-ii-database system concepts and architecture
Bsc cs ii-dbms- u-ii-database system concepts and architecture
 
SQL ARPIT YADAV.pptx
SQL ARPIT YADAV.pptxSQL ARPIT YADAV.pptx
SQL ARPIT YADAV.pptx
 
Unit 1 DBMS
Unit 1 DBMSUnit 1 DBMS
Unit 1 DBMS
 
SQL_Introduction_Updated.pptx
SQL_Introduction_Updated.pptxSQL_Introduction_Updated.pptx
SQL_Introduction_Updated.pptx
 
2nd chapter dbms.pptx
2nd chapter dbms.pptx2nd chapter dbms.pptx
2nd chapter dbms.pptx
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

Introduction to the Structured Query Language SQL

  • 1. 1 Database Systems Introduction to the Structured Query Language Harmony Kwawu hkwawu@aol.com Course Outline Introduction Use of database applications Database Management System Relational operators Purpose of relational database query SQL Commands: Data manipulation command Data definition command SQL Joins Summary
  • 2. 3 Introduction Our world depends on data and increasingly so, in order to thrive. There are many different methods used for storing data but the idea of relational database technology has proved the most advantageous A key benefit of relational database approach is the capacity to allow users to retrieve data from or interact with database in an intuitive and variant ways. At the heart of all major relational database approach is the SQL, standing for Structured Query Language. SQL is based on set theory or relational principles. Relational operators help developers write complex procedures to enforce business rules and enhance database interactivity There are six different types of relational operators used in major DBMS as illustrated in this brief introduction to the Structured Query Language But first …. Uses of Database Applications
  • 3. 24/01/2011 ©HKwawu 5 Uses of Database Applications • Databases are the backbone of all information systems. Examples of information system types include: • Patient appointment systems • Library customer registration and account management systems • Automatic Teller Machine (ATM) • Hotel reservation and bookings systems • Stock control systems, and • School information mgt systems (SIMS) Relational Database Systems
  • 4. Relational Database Systems There are different ways to store data. Data can be stored in files, documents, image and sound forms etc But relational database approach is the most versatile and convenient Relational database approach is one in which data is organised into sets or tables Where each table is linked to other tables to form a relational model. STUDENT Student_ID (PK) StudentName StudentAddress Email Telephone Comment Course_Code(FK) ModuleModule Module_Id(PK) Module Name Aim Outcome Course_Code (FK) Course_Code(PK) CourseName CourseDescription CourseCourse A simple illustrated example of relational data model.
  • 5. Relations Tables in a relational database are technically referred to as entities or relations. Key Components The main components of relational database systems are: The database or data repository consisting of: Individual tables linked to form a logical model Attributes of stored data Specific values or records Database Manager (BM) The command base for retrieving and managing the database (SQL) Applications for interacting with the content of the data base User interface
  • 6. Major benefits of Relational database systems Relational database approach also allow data from different parts of an organisation to be stored in one place This approach makes it easy to protect and control access to the database Also, storing data in a logically related tables can be accessed by different applications and users according to their needs SQL What is Database Management System
  • 7. 13 Database Management System (DBMS) A database management system (DBMS) is a large piece of software that is used in defining, creating, updating and deleting a database records. A database management system is also known as database manager It supports the operation of database applications within an integrated, controlled and accessible framework. Examples of DBMS are: MS Access Oracle PL/SQL MySQL 13 A simple Infographics of Database Management Systems
  • 8. Data Base Query Relational Database Operators Operators are generally used in programming and application development to build expressions. There are generally four categories of operators, namely: Arithmetic operators Relational or Boolean Operators Logical Operator Assignment Operator Relational operators are the most common type of operators used in relational database They are used to help write complex procedures to enforce business rules and construct query statements
  • 9. Data Base Query Database Relational Operators Common Database Relational Operators OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning ExampleExampleExampleExample = Equal to Gives exact value in a database <> Not equal to List values other than the one specified > Greater than List values that are greater than the one specified < Less than Shows values that are less than the one stated <= Less than or equal to Shows values stated and all values less than the one stated >= Greater than or equal to Shows values specified and all values greater than the one stated
  • 10. Other Database Relational Operators Cont.. OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning ExampleExampleExampleExample Between ......> And <..... Retrieve all values within the given range excluding the two values stated Between Between Retrieve all values within the given range including the two values stated OR ......OR ...... List one set of value or another The SQL Command
  • 11. 21 The SQL command We shall examine in future posts how the above operators are used to programme relational database, But first let’s discuss other aspect of database query-the SQL command. As noted above, SQL allow database users to retrieve data, update existing records, delete records, create index, create new tables and delete tables SQL statements can be interactive and embedded in third party programming languages, such as ASP.NET or PHP And SQL statement may be simple or complex, more on this in future 22 SQL Command In MS Access database management systems for example, queries are created using what is known as Access Query Design view. The queries created in design view can be viewed and edited to reflect changes It’s equally possible to write new query statements directly in SQL view Note that SQL Stand for structured query language and that SQL is the defector programming language for relational databases.
  • 12. 23 Illustrated Example: Query Design View A very simple query A local bank require the design of a system to store record of its clients and the loan they borrow. The system should be able to store details of the clients, details of loan and loan types and the branch for Each customer. A preliminary entity relation model has been produced by one of your database development team member as shown below: use the ERD to produce the following queries Bank customer loan processing system challenge
  • 13. 25 Illustrated Example: Query Design View Bank Database Model A slightly complex query SQL View in MS Access SQL Query statement
  • 14. SQL Command Types 28 SQL Command Types There are many categories of structured Query Language statements. For our purpose, we shall focus on two key categories as follows: The data definition language (DDL) commands, and Data manipulation language (DML) commands
  • 15. DDL and DML Data Definition Language (DDL) Are used to define and model the structure of data e.g. Create the database, Alter (make changes to the database) and Drop (delete database object) Data Manipulation Language (DML) Used mainly for interacting and manipulating stored data e.g. Select, Update, Delete and Insert new records into database Data Definition Language (DDL) Create statement Alter statement, and Drop statement
  • 16. 31 Example 1: SQL Create Table Command Create Table Staff( Staff_Id Number (10) NOT Null Staff_FirstName Varchar(30) NOT Null, Staff_SurName Varchar(30) NOT Null, Staff_Position Varchar(10) NOT Null, Staff_EmailVarchar(30) NOT Null, Staff_Telephone Varchar(30) NOT Null, Room_Number Varchar(30) NOT Null, Staff_Speciality Varchar(30) NOT Null, Constraints Staff_PK Primary Key (Staff_id)); The Result See if you can guess the result by sketching it
  • 17. 33 Example2: SQL Create Table Cont.. Create Table Course ( Course_Code Number (10) NOT Null, Course_Name Varchar(30) NOT Null, Course_Aim Varchar(30) NOT Null, Course_Description Varchar(100) NOT Null, Staff_Id Number (30), Constraints Course_PK Primary Key (Course_Code), CONSTRAINTS Staff_FK FOREIGN (Staff_Id), REFERENCES Staff(Staff)); The Result Again, see if you can guess the result by sketching it
  • 18. Other important DDL Statements Other important DDL Statements Alter statement and Drop statement Find out more from the link below: http://www.w3schools.com/sql/sql_alter.asp
  • 19. Data Manipulating Language Data Manipulating Language Select statement is perhaps the most important and frequently used data manipulation statement. Other equally important commands are: Update command Delete command Insert command The main purpose of DML, is to allow database users to retrieve (select) and or manipulate stored data
  • 20. Structure of select statement Below are what could be descried as the building blocks of simple select command: SELECT FROM Where Or Quiz Briefly describe what Each of the following select statement keywords means in practice? SELECT FROM Where Or
  • 21. Example of select statement: List the names and email address of all staff in room 123 SELECT (Staff_ID, First Name, Surname, Email, Telephone, Room FROM Staff, WHERE ((Room)=123)); The Result See if you can guess the result by sketching it
  • 22. 43 Data Manipulating Language Example of DML select statement-2: List Name and detail of students SELECT Student_ID, First_Name, Surname, Email, Mobile, Home_Tel FROM Student; The Result See if you can guess the result by sketching it
  • 23. 45 DML SQL Command List names of students and their course SELECT Student_ID, First_Name, Surname, D_O_B, Email,Course_Name, Description FROM Course INNER JOIN Student ON tblCourse.Course_ID=TblStudent.Course_ID; The Result Congratulation if you were able to guess the result correctly by sketching it
  • 24. 47 Other Types of DML Query Update Query in MS Access: Example 1: UPDATE TblStudent SET TblStudent.First_Name = "Null", TblStudent.Surname = “Null”, TblStudent.D_O_B = “Null”; Example 2: UPDATE TblJob_Type SET TblJob_Type.Charges = “£90"; Log on to the URL below to find out more: http://www.w3schools.com/sql/sql_update.asp
  • 25. 49 Delete Query in MS Access Delete all record from the Module Table DELETE * FROM TblModules; 50 Insert data into table INSERT INTO Student (Student_Name,Student_Address,Email) Values (Joe Williams, London Road, JW@Yahoo.com); INSERT INTO Student (Student_Name,Student_Address,Email) Values (Henry Champion, West Kent Road, HC@Yahoo.com); INSERT INTO Student (Student_Name,Student_Address,Email) Values (Mark Williams, China Town, MW@Yahoo.com);
  • 26. 51 Project Report 1 52 SQL Report1 SELECT Projects_Tbl.Project_Id,Projects_Tbl.Project_Name, Employees_Tbl.Employee_No,Employees_Tbl.Employee_Na me, Job_Type_Tbl.Job_Class, Job_Type_Tbl.Charges, Employee_Project_Tbl.Hours FROM (Projects_Tbl INNER JOIN (Employees_Tbl INNER JOIN Employee_Project_Tbl ON Employees_Tbl.Employee_No=Employee_Project_Tbl.Emply ee_Number) ON Projects_Tbl.Project_Id=Employee_Project_Tbl.Project_id) INNER JOIN Job_Type_Tbl ON Projects_Tbl.Project_Id=Job_Type_Tbl.Project_Id;
  • 27. Output report Try and sketch what you think the output is likely to be 54 Project Report 2 Fig: Select Query to generate the report below Fig: Result of the query
  • 28. 55 SQL Report 2 SELECT Projects_Tbl.Project_Id, Projects_Tbl.Project_Name, Employees_Tbl.Employee_No, Employees_Tbl.Employee_Name, Job_Type_Tbl.Job_Class, Job_Type_Tbl.Charges, Employee_Project_Tbl.Hours, [Charges]*[hours] AS Total FROM (Projects_Tbl INNER JOIN (Employees_Tbl INNER JOIN Employee_Project_Tbl ON Employees_Tbl.Employee_No = Employee_Project_Tbl.Emplyee_Number) ON Projects_Tbl.Project_Id = Employee_Project_Tbl.Project_id) INNER JOIN Job_Type_Tbl ON Projects_Tbl.Project_Id = Job_Type_Tbl.Project_Id; 56 Write SQL Query to implement the following two Tables. You may use MS Access Query design to help you complete this task. The tables are based on the Project/Employee database Table: 1 Table: 2 Try this revision task
  • 29. 57 Joins Statements SQL join commands are useful when querying data from multiple tables that are linked together 58 Joins Statements Cont’.. Types of joins: INNER JOIN (JOIN): Return rows when there is at least one match in both tables LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table FULL JOIN: Return rows when there is a match in one of the tables See the sites below for further details on joins: http://infogoal.com/sql/sql-outer-join.htm http://www.w3schools.com/sql/sql_join_inner.asp
  • 30. 59 Summary In this post, we’ve learnt that SQL is a command based language which allow database developers to create and manipulate stored record SQL can be used to create the database, make changes to the database and delete database objects SQL also help users to interact and manipulate stored data. Users can make a request (declare) for the data they require without the need to specify how the request should be processed SQL is a powerful language to learn as it is the most popular programming language for relational database applications Next Post Advance SQL
  • 31. Additional SQL online tutorials you! Introduction to SQL: http://www.w3schools.com/sql/sql_intro.asp End Feel free to get in touch if you would like to share your thought on this topic. You can contact me by email at: hkwawu@aol.com