SlideShare a Scribd company logo
“Database Management Systems”
CS-222
Lecture 17
“Structured Query Language (SQL)”
Dr. Muhammad Muneer Umar
By:
Lecturer in Computer Science
Institute of Computing
KUST, Pakistan
Objective of the today’s topic
• To know the fundamentals about Structure Query Language (SQL)
• To know the importance and usability of SQL in RDBMS
• To understand the basic syntax of SQL code
• To define SQL statements, clauses and keywords
• To learn about the utilization and management of RDBMS through SQL
• To understand the categories of SQL statements
CONTENTS
• Introduction
• What can SQL do with databases?
• SQL Query
• SQL statements, clauses and keywords
• Rules for typing SQL statements
• SQL commands
• DDL: Data Definition Language
• DML: Data Manipulation Language
• TCL: Transaction Control Language
• DCL: Data Control Language
• DQL: Data Query Language
INTRODUCTION
• “Structure Query Language(SQL) is a database query language used for storing and
managing data in Relational DBMS”.
• First commercial language introduced for E.F Codd's Relational model of database.
• Standardization:
• American National Standards Institute (ANSI) in 1986,
• International Organization for Standardization (ISO) in 1987
• Used by almost all RDBMS(MySql, Oracle, Infomix, Sybase, MS Access)
RELATIONS IN SQL
PName Price Category Manufacturer
Gizmo $19.99 Gadgets GizmoWorks
Powergizmo $29.99 Gadgets GizmoWorks
SingleTouch $149.99 Photography Canon
MultiTouch $203.99 Household Hitachi
Product
Attribute names
Table name
Tuples or rows
What can SQL do with databases?
Execute
queries
against a
database
Retrieve data
from a
database
Insert records
in a database
Update
records in a
database
Delete
records from
a database
Create new
databases
Create new
tables in a
database
Create stored
procedures in
a database
Create views
in a database
Set permissions
on tables,
procedures, and
views
SQL QUERY
BASIC FORM:
SELECT <attributes>
FROM <one or more relations>
WHERE <conditions>
SAMPLES:
SELECT reg, sname
FROM student_table
WHERE city = ‘Kohat’ ;
INSERT INTO student_table (reg, sname, city)
VALUES (‘CS123456’ , ‘Farhan’ , ‘Kohat’ );
DROP TABLE student_table ;
SHOW TABLES ;
SQL STATEMENTS, CLAUSES AND KEYWORDS
SELECT std_id, std_name, std_age FROM student ORDER BY std_id;
1) KEYWORD
The individual tokens (elements) which are predefined,
and we cannot change their meaning are known as SQL
keyword.
In the given example: The keyword are "SELECT" ,
"FROM“ and “ORDER BY” 2) CLAUSE
Clause is a part of an SQL statement.
In the given example: The clause are
"SELECT std_id, std_name, std_age“
and
“ORDER BY std_id”
3) STATEMENT
A complete query may refer to as a "statement" and we
can say that set of two or more clause are known as a
"statement" in SQL.
RULES FOR TYPING SQL STATEMENTS
• SQL statement is not case sensitive you may write the statement in any
case (even keywords like SELECT, FROM, DROP etc.) are not case
sensitive.
• You can write a complete SQL statement in a single line (but, you
should separate them in multiple lines, each clause should be written in
separate line).
• You may use to enhance the SQL Query readability.
Note: keywords should be written in UPPERCASE (for better readability)
and other words should be written in lowercase.
RULES FOR TYPING SQL STATEMENTS
• SAME:
• SELECT  Select  select
• Product  product
• CONSTANTS/VALUES:
• Correct  ‘abc’
• Wrong  “abc”
• Use single quote (‘) for strings/character values
• ‘Ahmed Khan’ , ‘Peshawar’ , ‘+92-3331234567
• Use grave accent (`) for object names
• `table_name` , `std_info_view` , `procedure1`
DIFFERENT:
‘Ali’  ‘ali’
SQL COMMANDS
• SQL defines following ways to manipulate data stored in an RDBMS.
• DDL: Data Definition Language
• DML: Data Manipulation Language
• TCL: Transaction Control Language
• DCL: Data Control Language
• DQL: Data Query Language
DDL: Data Definition Language
• This includes changes to the structure of the table
• like creation of table, altering table, deleting a table etc.
• All DDL commands are auto-committed.
• That means it saves all the changes permanently in the database
Command Description
CREATE to create new table or database
ALTER for alteration
TRUNCATE delete data from table
DROP to drop a table
RENAME to rename a table
DML: Data Manipulation Language
• DML commands are used for manipulating the data stored in the table
and not the table itself.
• DML commands are not auto-committed.
• It means changes are not permanent to database, they can be rolled back.
Command Description
INSERT to insert a new row
UPDATE to update existing row
DELETE to delete a row
MERGE merging two rows or two tables
TCL: Transaction Control Language
• These commands are to keep a check on other commands and their
affect on the database.
• It can also make any temporary change permanent.
Command Description
COMMIT to permanently save
ROLLBACK to undo change
SAVEPOINT to save temporarily
DCL: Data Control Language
• Data control language are the commands to grant and take back
authority from any database user.
Command Description
GRANT grant permission of right
REVOKE take back permission.
DQL: Data Query Language
• Data query language is used to fetch data from tables based on
conditions that we can easily apply
Command Description
SELECT retrieve records from one or more table
SUMMARY
• SQL: A language used for management of RDBMS
• SQL can be used to perform various operations on RDBMS
• Also we can do managerial task with SQL
• SQL is not case sensitive.
• SQL commands can be classified as:
• DDL, DML, TCL, DCL, DQL
THANKS
Sample Queries (Practice in Workbench):
• Select a database
• Select Data from Database Table
• Insert Data into a table
• Update existing data
• Delete data from a table
• Create a new table

More Related Content

Similar to Lecture 9 (Week 8) - Structured Query Language (SQL).pptx (20)

PPTX
Unit - II.pptx
MrsSavitaKumbhare
 
PPTX
Using Basic Structured Query Language lo1.pptx
TsedaleBayabil
 
PPTX
CapCut Pro 6.0.0.2434 Crack For PC Free Download [2025]
haz643985
 
PPTX
Rekordbox DJ 7.1.1 Crack Free Download (Latest)
haz643985
 
PPTX
SQL2.pptx
RareDeath
 
PPTX
An intoduction to sql and its components
Monika Jain DAIMSR
 
PPTX
SQL OVERVIEW for a new introduced student.pptx
JosephNhlane
 
PDF
Sql tutorial
Rumman Ansari
 
PDF
SQL Basics, DDL, DML, DQL, Learn The BAsics Of SQL.pdf
JavairiaRaza1
 
PPTX
BWU_BTA_22_403_Aishika Majumdar and all about cse
SandipPradhan23
 
PPTX
SQLBasic to advance for the beggineers.pptx
testvarun21
 
PPTX
Lecture - MY-SQL/ SQL Commands - DDL.pptx
umershah0263
 
PDF
sql notes Provideby AGN HUB Tech & It Solutions
mohanagn2244
 
PDF
Database Systems - Introduction to SQL (Chapter 3/1)
Vidyasagar Mundroy
 
PDF
Dms 22319 micro project
ARVIND SARDAR
 
PPTX
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
FayChan8
 
PDF
Introduction to SQL..pdf
mayurisonawane29
 
PPTX
Introduction to SQL.pptx
shubhidas
 
PPTX
Structured query language
Rashid Ansari
 
PPTX
Sql queries
sabapathi shanmugam
 
Unit - II.pptx
MrsSavitaKumbhare
 
Using Basic Structured Query Language lo1.pptx
TsedaleBayabil
 
CapCut Pro 6.0.0.2434 Crack For PC Free Download [2025]
haz643985
 
Rekordbox DJ 7.1.1 Crack Free Download (Latest)
haz643985
 
SQL2.pptx
RareDeath
 
An intoduction to sql and its components
Monika Jain DAIMSR
 
SQL OVERVIEW for a new introduced student.pptx
JosephNhlane
 
Sql tutorial
Rumman Ansari
 
SQL Basics, DDL, DML, DQL, Learn The BAsics Of SQL.pdf
JavairiaRaza1
 
BWU_BTA_22_403_Aishika Majumdar and all about cse
SandipPradhan23
 
SQLBasic to advance for the beggineers.pptx
testvarun21
 
Lecture - MY-SQL/ SQL Commands - DDL.pptx
umershah0263
 
sql notes Provideby AGN HUB Tech & It Solutions
mohanagn2244
 
Database Systems - Introduction to SQL (Chapter 3/1)
Vidyasagar Mundroy
 
Dms 22319 micro project
ARVIND SARDAR
 
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
FayChan8
 
Introduction to SQL..pdf
mayurisonawane29
 
Introduction to SQL.pptx
shubhidas
 
Structured query language
Rashid Ansari
 
Sql queries
sabapathi shanmugam
 

Recently uploaded (20)

PDF
apidays Singapore 2025 - Trustworthy Generative AI: The Role of Observability...
apidays
 
PPTX
apidays Helsinki & North 2025 - Vero APIs - Experiences of API development in...
apidays
 
PDF
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PDF
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
PPTX
Listify-Intelligent-Voice-to-Catalog-Agent.pptx
nareshkottees
 
PPTX
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
PPTX
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
PDF
OPPOTUS - Malaysias on Malaysia 1Q2025.pdf
Oppotus
 
PDF
apidays Helsinki & North 2025 - Monetizing AI APIs: The New API Economy, Alla...
apidays
 
PDF
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
PPT
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
PDF
apidays Singapore 2025 - The API Playbook for AI by Shin Wee Chuang (PAND AI)
apidays
 
PPTX
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
PPT
AI Future trends and opportunities_oct7v1.ppt
SHIKHAKMEHTA
 
PPTX
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
PDF
OOPs with Java_unit2.pdf. sarthak bookkk
Sarthak964187
 
PDF
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
PPTX
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
apidays Singapore 2025 - Trustworthy Generative AI: The Role of Observability...
apidays
 
apidays Helsinki & North 2025 - Vero APIs - Experiences of API development in...
apidays
 
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
Listify-Intelligent-Voice-to-Catalog-Agent.pptx
nareshkottees
 
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
OPPOTUS - Malaysias on Malaysia 1Q2025.pdf
Oppotus
 
apidays Helsinki & North 2025 - Monetizing AI APIs: The New API Economy, Alla...
apidays
 
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
apidays Singapore 2025 - The API Playbook for AI by Shin Wee Chuang (PAND AI)
apidays
 
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
AI Future trends and opportunities_oct7v1.ppt
SHIKHAKMEHTA
 
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
OOPs with Java_unit2.pdf. sarthak bookkk
Sarthak964187
 
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
Ad

Lecture 9 (Week 8) - Structured Query Language (SQL).pptx

  • 1. “Database Management Systems” CS-222 Lecture 17 “Structured Query Language (SQL)” Dr. Muhammad Muneer Umar By: Lecturer in Computer Science Institute of Computing KUST, Pakistan
  • 2. Objective of the today’s topic • To know the fundamentals about Structure Query Language (SQL) • To know the importance and usability of SQL in RDBMS • To understand the basic syntax of SQL code • To define SQL statements, clauses and keywords • To learn about the utilization and management of RDBMS through SQL • To understand the categories of SQL statements
  • 3. CONTENTS • Introduction • What can SQL do with databases? • SQL Query • SQL statements, clauses and keywords • Rules for typing SQL statements • SQL commands • DDL: Data Definition Language • DML: Data Manipulation Language • TCL: Transaction Control Language • DCL: Data Control Language • DQL: Data Query Language
  • 4. INTRODUCTION • “Structure Query Language(SQL) is a database query language used for storing and managing data in Relational DBMS”. • First commercial language introduced for E.F Codd's Relational model of database. • Standardization: • American National Standards Institute (ANSI) in 1986, • International Organization for Standardization (ISO) in 1987 • Used by almost all RDBMS(MySql, Oracle, Infomix, Sybase, MS Access)
  • 5. RELATIONS IN SQL PName Price Category Manufacturer Gizmo $19.99 Gadgets GizmoWorks Powergizmo $29.99 Gadgets GizmoWorks SingleTouch $149.99 Photography Canon MultiTouch $203.99 Household Hitachi Product Attribute names Table name Tuples or rows
  • 6. What can SQL do with databases? Execute queries against a database Retrieve data from a database Insert records in a database Update records in a database Delete records from a database Create new databases Create new tables in a database Create stored procedures in a database Create views in a database Set permissions on tables, procedures, and views
  • 7. SQL QUERY BASIC FORM: SELECT <attributes> FROM <one or more relations> WHERE <conditions> SAMPLES: SELECT reg, sname FROM student_table WHERE city = ‘Kohat’ ; INSERT INTO student_table (reg, sname, city) VALUES (‘CS123456’ , ‘Farhan’ , ‘Kohat’ ); DROP TABLE student_table ; SHOW TABLES ;
  • 8. SQL STATEMENTS, CLAUSES AND KEYWORDS SELECT std_id, std_name, std_age FROM student ORDER BY std_id; 1) KEYWORD The individual tokens (elements) which are predefined, and we cannot change their meaning are known as SQL keyword. In the given example: The keyword are "SELECT" , "FROM“ and “ORDER BY” 2) CLAUSE Clause is a part of an SQL statement. In the given example: The clause are "SELECT std_id, std_name, std_age“ and “ORDER BY std_id” 3) STATEMENT A complete query may refer to as a "statement" and we can say that set of two or more clause are known as a "statement" in SQL.
  • 9. RULES FOR TYPING SQL STATEMENTS • SQL statement is not case sensitive you may write the statement in any case (even keywords like SELECT, FROM, DROP etc.) are not case sensitive. • You can write a complete SQL statement in a single line (but, you should separate them in multiple lines, each clause should be written in separate line). • You may use to enhance the SQL Query readability. Note: keywords should be written in UPPERCASE (for better readability) and other words should be written in lowercase.
  • 10. RULES FOR TYPING SQL STATEMENTS • SAME: • SELECT  Select  select • Product  product • CONSTANTS/VALUES: • Correct  ‘abc’ • Wrong  “abc” • Use single quote (‘) for strings/character values • ‘Ahmed Khan’ , ‘Peshawar’ , ‘+92-3331234567 • Use grave accent (`) for object names • `table_name` , `std_info_view` , `procedure1` DIFFERENT: ‘Ali’  ‘ali’
  • 11. SQL COMMANDS • SQL defines following ways to manipulate data stored in an RDBMS. • DDL: Data Definition Language • DML: Data Manipulation Language • TCL: Transaction Control Language • DCL: Data Control Language • DQL: Data Query Language
  • 12. DDL: Data Definition Language • This includes changes to the structure of the table • like creation of table, altering table, deleting a table etc. • All DDL commands are auto-committed. • That means it saves all the changes permanently in the database Command Description CREATE to create new table or database ALTER for alteration TRUNCATE delete data from table DROP to drop a table RENAME to rename a table
  • 13. DML: Data Manipulation Language • DML commands are used for manipulating the data stored in the table and not the table itself. • DML commands are not auto-committed. • It means changes are not permanent to database, they can be rolled back. Command Description INSERT to insert a new row UPDATE to update existing row DELETE to delete a row MERGE merging two rows or two tables
  • 14. TCL: Transaction Control Language • These commands are to keep a check on other commands and their affect on the database. • It can also make any temporary change permanent. Command Description COMMIT to permanently save ROLLBACK to undo change SAVEPOINT to save temporarily
  • 15. DCL: Data Control Language • Data control language are the commands to grant and take back authority from any database user. Command Description GRANT grant permission of right REVOKE take back permission.
  • 16. DQL: Data Query Language • Data query language is used to fetch data from tables based on conditions that we can easily apply Command Description SELECT retrieve records from one or more table
  • 17. SUMMARY • SQL: A language used for management of RDBMS • SQL can be used to perform various operations on RDBMS • Also we can do managerial task with SQL • SQL is not case sensitive. • SQL commands can be classified as: • DDL, DML, TCL, DCL, DQL
  • 19. Sample Queries (Practice in Workbench): • Select a database • Select Data from Database Table • Insert Data into a table • Update existing data • Delete data from a table • Create a new table