SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
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)
Punjab University
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
Ranjit273515
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
Aditya Kumar Tripathy
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
Varun A M
 
Top 65 SQL Interview Questions and Answers | Edureka
Top 65 SQL Interview Questions and Answers | EdurekaTop 65 SQL Interview Questions and Answers | Edureka
Top 65 SQL Interview Questions and Answers | Edureka
Edureka!
 
Conceptual Data Modeling
Conceptual Data ModelingConceptual Data Modeling
Conceptual Data Modeling
Dr. Thippeswamy S.
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
pnp @in
 
SQL: Structured Query Language
SQL: Structured Query LanguageSQL: Structured Query Language
SQL: Structured Query Language
Rohit Bisht
 
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTUREMS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
Mohd Tousif
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
Edureka!
 
Sql a practical introduction
Sql   a practical introductionSql   a practical introduction
Sql a practical introduction
Hasan Kata
 
Sql ppt
Sql pptSql ppt
Sql ppt
Anuja Lad
 
Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
Arpee Callejo
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
Dhananjay Goel
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
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)
Punjab University
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
Varun A M
 
Top 65 SQL Interview Questions and Answers | Edureka
Top 65 SQL Interview Questions and Answers | EdurekaTop 65 SQL Interview Questions and Answers | Edureka
Top 65 SQL Interview Questions and Answers | Edureka
Edureka!
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
pnp @in
 
SQL: Structured Query Language
SQL: Structured Query LanguageSQL: Structured Query Language
SQL: Structured Query Language
Rohit Bisht
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
Mohd Tousif
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
Edureka!
 
Sql a practical introduction
Sql   a practical introductionSql   a practical introduction
Sql a practical introduction
Hasan Kata
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
Arpee Callejo
 

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

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
 
Data base
Data baseData base
Data base
Girish Gowda
 
a presenation on various dtabase languages
a presenation on various dtabase languagesa presenation on various dtabase languages
a presenation on various dtabase languages
nidhi5172
 
sql ppt.pptx
sql ppt.pptxsql ppt.pptx
sql ppt.pptx
ArunT58
 
Introduction to sql server
Introduction to sql serverIntroduction to sql server
Introduction to sql server
Vinay Thota
 
Chapter02
Chapter02Chapter02
Chapter02
sasa_eldoby
 
Sql server
Sql serverSql server
Sql server
Puja Gupta
 
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
maqsoodahmedbscsfkhp
 
Chapter Five Physical Database Design.pptx
Chapter Five Physical Database Design.pptxChapter Five Physical Database Design.pptx
Chapter Five Physical Database Design.pptx
haymanot taddesse
 
DBMS. Advantage of Data base management systems
DBMS. Advantage of Data base management systemsDBMS. Advantage of Data base management systems
DBMS. Advantage of Data base management systems
Dr Shailendra Bhalawe
 
Sql ppt
Sql pptSql ppt
Sql ppt
Prof. Dr. K. Adisesha
 
Introduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQLIntroduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQL
Collaboration Technologies
 
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
Rai University
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
Steven Johnson
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
NIVETHA37590
 
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
Rai University
 
SQL commands in database managemant systems
SQL commands in database managemant systemsSQL commands in database managemant systems
SQL commands in database managemant systems
pmselvaraj
 
SQL ARPIT YADAV.pptx
SQL ARPIT YADAV.pptxSQL ARPIT YADAV.pptx
SQL ARPIT YADAV.pptx
ArpitYadav353999
 
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
 
a presenation on various dtabase languages
a presenation on various dtabase languagesa presenation on various dtabase languages
a presenation on various dtabase languages
nidhi5172
 
sql ppt.pptx
sql ppt.pptxsql ppt.pptx
sql ppt.pptx
ArunT58
 
Introduction to sql server
Introduction to sql serverIntroduction to sql server
Introduction to sql server
Vinay Thota
 
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
maqsoodahmedbscsfkhp
 
Chapter Five Physical Database Design.pptx
Chapter Five Physical Database Design.pptxChapter Five Physical Database Design.pptx
Chapter Five Physical Database Design.pptx
haymanot taddesse
 
DBMS. Advantage of Data base management systems
DBMS. Advantage of Data base management systemsDBMS. Advantage of Data base management systems
DBMS. Advantage of Data base management systems
Dr Shailendra Bhalawe
 
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
Rai University
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
Steven Johnson
 
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
Rai University
 
SQL commands in database managemant systems
SQL commands in database managemant systemsSQL commands in database managemant systems
SQL commands in database managemant systems
pmselvaraj
 
Ad

Recently uploaded (20)

HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Ad

Introduction to the Structured Query Language SQL

  • 1. 1 Database Systems Introduction to the Structured Query Language Harmony Kwawu [email protected] 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, [email protected]); INSERT INTO Student (Student_Name,Student_Address,Email) Values (Henry Champion, West Kent Road, [email protected]); INSERT INTO Student (Student_Name,Student_Address,Email) Values (Mark Williams, China Town, [email protected]);
  • 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: [email protected]