SlideShare a Scribd company logo
SQL(Structured Query
Language)
Overview
Introduction
DDL Commands
DML Commands
SQL Statements, Operators, Clauses
Aggregate Functions
Difference between DBMS and RDBMS
S.N DBMS TDBMS
1
Introduced in 1960s. Introduced in 1970s.
2 During introduction it followed the
navigational modes (Navigational
DBMS) for data storage and
fetching.
This model uses relationship
between tables using primary keys,
foreign keys .
3 Data fetching is slower for
complex and large amount of data.
Comparatively faster because of its
relational model.
4 Used for applications using small
amount of data.
Used for complex and large amount
of data.
5 Data Redundancy is common in
this model
Keys and indexes are used in the
tables to avoid redundancy.
6 Example systems are dBase,,
LibreOffice Base, FoxPro.
Example systems are SQL Server,
Oracle ,MS ACESS, MySQL,
MariaDB, SQLite.
The ANSI standard language for the definition and
manipulation of relational database.
Includes data definition language (DDL), statements that
specify and modify database schemas.
Includes a data manipulation language (DML), statements
that manipulate database content.
Structured Query Language (SQL)
Some Facts on SQL
SQL data is case-sensitive, SQL commands are not.
First Version was developed at IBM by Donald D.
Chamberlin and Raymond F. Boyce. [SQL]
Developed using Dr. E.F. Codd's paper, “A Relational Model
of Data for Large Shared Data Banks.”
SQL query includes references to tuples variables and the
attributes of those variables
SQL: DDL Commands
CREATE TABLE: used to create a table.
ALTER TABLE: modifies a table after it was created.
DROP TABLE: removes a table from a database.
SQL: CREATE TABLE Statement
Things to consider before you create your table are:
The type of data
the table name
what column(s) will make up the primary key
the names of the columns
CREATE TABLE statement syntax:
CREATE TABLE <table name>
( field1 datatype ( NOT NULL ),
field2 datatype ( NOT NULL )
);
SQL: Attributes Types
SQL: ALTER TABLE Statement
To add or drop columns on existing tables.
ALTER TABLE statement syntax:
ALTER TABLE <table name>
ADD attr datatype;
or
DROP COLUMN attr;
SQL: DROP TABLE Statement
DROP TABLE statement syntax:
DROP TABLE <table name> ;
Example:
CREATE TABLE FoodCart (
date varchar(10),
food varchar(20),
profit float
);
ALTER TABLE FoodCart (
ADD sold int
);
ALTER TABLE FoodCart(
DROP COLUMN profit
);
DROP TABLE FoodCart;
profit
food
date
sold
profit
food
date
sold
food
date
FoodCart
FoodCart
FoodCart
SQL: DML Commands
INSERT: adds new rows to a table.
UPDATE: modifies one or more attributes.
DELETE: deletes one or more rows from a table.
SQL: INSERT Statement
To insert a row into a table, it is necessary to have a value
for each attribute, and order matters.
INSERT statement syntax:
INSERT into <table name>
VALUES ('value1', 'value2', NULL);
Example: INSERT into FoodCart
VALUES (’02/26/08', ‘pizza', 70 );
FoodCart
70
pizza
02/26/08
500
hotdog
02/26/08
350
pizza
02/25/08
sold
food
date
500
hotdog
02/26/08
350
pizza
02/25/08
sold
food
date
SQL: UPDATE Statement
To update the content of the table:
UPDATE statement syntax:
UPDATE <table name> SET <attr> = <value>
WHERE <selection condition>;
Example: UPDATE FoodCart SET sold = 349
WHERE date = ’02/25/08’AND food = ‘pizza’;
FoodCart
70
pizza
02/26/08
500
hotdog
02/26/08
350
pizza
02/25/08
sold
food
date
70
pizza
02/26/08
500
hotdog
02/26/08
349
pizza
02/25/08
sold
food
date
SQL: DELETE Statement
To delete rows from the table:
DELETE statement syntax:
DELETE FROM <table name>
WHERE <condition>;
Example: DELETE FROM FoodCart
WHERE food = ‘hotdog’;
FoodCart
Note: If the WHERE clause is omitted all rows of data are deleted from the table.
70
pizza
02/26/08
500
hotdog
02/26/08
349
pizza
02/25/08
sold
food
date
70
pizza
02/26/08
349
pizza
02/25/08
sold
food
date
SQL Statements, Operations, Clauses
SQL Statements:
Select
SQL Operations:
Join
Left Join
Right Join
Like
SQL Clauses:
Order By
Group By
Having
SQL: SELECT Statement
A basic SELECT statement includes 3 clauses
SELECT <attribute name> FROM <tables> WHERE <condition>
SELECT
Specifies the attributes
that are part of the
resulting relation
FROM
Specifies the tables
that serve as the input
to the statement
WHERE
Specifies the selection
condition, including
the join condition.
Using a “*” in a select statement indicates that every
attribute of the input table is to be selected.
Example: SELECT * FROM … WHERE …;
To get unique rows, type the keyword DISTINCT after
SELECT.
Example: SELECT DISTINCT * FROM …
WHERE …;
SQL: SELECT Statement (cont.)
Example:
Person
80
34
Peter
54
54
Helena
70
29
George
64
28
Sally
80
34
Harry
Weight
Age
Name
80
34
Peter
54
54
Helena
80
34
Harry
Weight
Age
Name
80
54
80
Weight
1) SELECT *
FROM person
WHERE age > 30;
2) SELECT weight
FROM person
WHERE age > 30;
3) SELECT distinct weight
FROM person
WHERE age > 30;
54
80
Weight
SQL: Join operation
A join can be specified in the FROM clause which
list the two input relations and the WHERE clause
which lists the join condition.
Example:
Biotech
1003
Sales
1002
IT
1001
Division
ID
TN
1002
MA
1001
CA
1000
State
ID
Emp Dept
SQL: Join operation (cont.)
Sales
1002
IT
1001
Dept.Division
Dept.ID
TN
1002
MA
1001
Emp.State
Emp.ID
inner join = join
SELECT *
FROM emp join dept (or FROM emp, dept)
on emp.id = dept.id;
SQL: Join operation (cont.)
IT
1001
Sales
1002
null
null
Dept.Division
Dept.ID
CA
1000
TN
1002
MA
1001
Emp.State
Emp.ID
left outer join = left join
SELECT *
FROM emp left join dept
on emp.id = dept.id;
SQL: Join operation (cont.)
Sales
1002
Biotech
1003
IT
1001
Dept.Division
Dept.ID
MA
1001
null
null
TN
1002
Emp.State
Emp.ID
right outer join = right join
SELECT *
FROM emp right join dept
on emp.id = dept.id;
SQL: Like operation
Pattern matching selection
% (arbitrary string)
SELECT *
FROM emp
WHERE ID like ‘%01’;
finds ID that ends with 01, e.g. 1001, 2001, etc
_ (a single character)
SELECT *
FROM emp
WHERE ID like ‘_01_’;
finds ID that has the second and third character as 01, e.g.
1010, 1011, 1012, 1013, etc
SQL: The ORDER BY Clause
Ordered result selection
desc (descending order)
SELECT *
FROM emp
order by state desc
puts state in descending order, e.g. TN, MA, CA
asc (ascending order)
SELECT *
FROM emp
order by id asc
puts ID in ascending order, e.g. 1001, 1002, 1003
SQL: The GROUP BY Clause
The function to divide the tuples into groups and returns an
aggregate for each group.
Usually, it is an aggregate function’s companion
SELECT food, sum(sold) as totalSold
FROM FoodCart
group by food;
FoodCart
419
pizza
500
hotdog
totalSold
food
70
pizza
02/26/08
500
hotdog
02/26/08
349
pizza
02/25/08
sold
food
date
SQL: The HAVING Clause
The substitute of WHERE for aggregate functions
Usually, it is an aggregate function’s companion
SELECT food, sum(sold) as totalSold
FROM FoodCart
group by food
having sum(sold) > 450;
FoodCart
500
hotdog
totalSold
food
70
pizza
02/26/08
500
hotdog
02/26/08
349
pizza
02/25/08
sold
food
date
SQL: Aggregate Functions
Are used to provide summarization information for SQL
statements, which return a single value.
COUNT(attr)
SUM(attr)
MAX(attr)
MIN(attr)
AVG(attr)
Note: when using aggregate functions, NULL values are not
considered, except in COUNT(*) .
SQL: Aggregate Functions (cont.)
COUNT(attr) -> return # of rows that are not null
Ex: COUNT(distinct food) from FoodCart; -> 2
SUM(attr) -> return the sum of values in the attr
Ex: SUM(sold) from FoodCart; -> 919
MAX(attr) -> return the highest value from the attr
Ex: MAX(sold) from FoodCart; -> 500
70
pizza
02/26/08
500
hotdog
02/26/08
349
pizza
02/25/08
sold
food
date
FoodCart
SQL: Aggregate Functions (cont.)
MIN(attr) -> return the lowest value from the attr
Ex: MIN(sold) from FoodCart; -> 70
AVG(attr) -> return the average value from the attr
Ex: AVG(sold) from FoodCart; -> 306.33
Note: value is rounded to the precision of the datatype
70
pizza
02/26/08
500
hotdog
02/26/08
349
pizza
02/25/08
sold
food
date
FoodCart

More Related Content

What's hot

SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
DML Commands
DML CommandsDML Commands
joins in database
 joins in database joins in database
joins in database
Sultan Arshad
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
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
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
Rayhan Chowdhury
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)yourbookworldanil
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Sql ppt
Sql pptSql ppt
Database
DatabaseDatabase
Database language
Database languageDatabase language
SQL
SQLSQL
Query optimization
Query optimizationQuery optimization
Query optimization
Neha Behl
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
Ravinder Kamboj
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 

What's hot (20)

SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
DML Commands
DML CommandsDML Commands
DML Commands
 
joins in database
 joins in database joins in database
joins in database
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
SQL commands
SQL commandsSQL commands
SQL commands
 
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)
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Database
DatabaseDatabase
Database
 
Database language
Database languageDatabase language
Database language
 
SQL
SQLSQL
SQL
 
Query optimization
Query optimizationQuery optimization
Query optimization
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 

Similar to SQL.ppt

Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
Linux international training Center
 
SQL Query
SQL QuerySQL Query
SQL Query
Imam340267
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql newSANTOSH RATH
 
Sql basic best-course-in-mumbai
Sql basic best-course-in-mumbaiSql basic best-course-in-mumbai
Sql basic best-course-in-mumbai
vibrantuser
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
Sql basic things
Sql basic thingsSql basic things
Sql basic things
Nishil Jain
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
Lab
LabLab
Module 3
Module 3Module 3
Module 3
cs19club
 
SQL
SQLSQL
Lab_04.ppt opreating system of computer lab
Lab_04.ppt opreating system of computer labLab_04.ppt opreating system of computer lab
Lab_04.ppt opreating system of computer lab
MUHAMMADANSAR76
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
Rishab Saini
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 

Similar to SQL.ppt (20)

Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
Sql basic best-course-in-mumbai
Sql basic best-course-in-mumbaiSql basic best-course-in-mumbai
Sql basic best-course-in-mumbai
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Sql basic things
Sql basic thingsSql basic things
Sql basic things
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Lab
LabLab
Lab
 
Module 3
Module 3Module 3
Module 3
 
SQL
SQLSQL
SQL
 
Lab_04.ppt opreating system of computer lab
Lab_04.ppt opreating system of computer labLab_04.ppt opreating system of computer lab
Lab_04.ppt opreating system of computer lab
 
Query
QueryQuery
Query
 
Sql
SqlSql
Sql
 
Sql
SqlSql
Sql
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 

More from Ranjit273515

dbms keys.pptx
dbms keys.pptxdbms keys.pptx
dbms keys.pptx
Ranjit273515
 
41- Ranjit CE 4th Sem.(P and I Notes).pdf
41- Ranjit CE 4th Sem.(P and I Notes).pdf41- Ranjit CE 4th Sem.(P and I Notes).pdf
41- Ranjit CE 4th Sem.(P and I Notes).pdf
Ranjit273515
 
question3.pdf
question3.pdfquestion3.pdf
question3.pdf
Ranjit273515
 
question3.pdf
question3.pdfquestion3.pdf
question3.pdf
Ranjit273515
 
question2.pdf
question2.pdfquestion2.pdf
question2.pdf
Ranjit273515
 
dbms notes.ppt
dbms notes.pptdbms notes.ppt
dbms notes.ppt
Ranjit273515
 

More from Ranjit273515 (6)

dbms keys.pptx
dbms keys.pptxdbms keys.pptx
dbms keys.pptx
 
41- Ranjit CE 4th Sem.(P and I Notes).pdf
41- Ranjit CE 4th Sem.(P and I Notes).pdf41- Ranjit CE 4th Sem.(P and I Notes).pdf
41- Ranjit CE 4th Sem.(P and I Notes).pdf
 
question3.pdf
question3.pdfquestion3.pdf
question3.pdf
 
question3.pdf
question3.pdfquestion3.pdf
question3.pdf
 
question2.pdf
question2.pdfquestion2.pdf
question2.pdf
 
dbms notes.ppt
dbms notes.pptdbms notes.ppt
dbms notes.ppt
 

Recently uploaded

Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 

Recently uploaded (20)

Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 

SQL.ppt

  • 2. Overview Introduction DDL Commands DML Commands SQL Statements, Operators, Clauses Aggregate Functions
  • 3. Difference between DBMS and RDBMS S.N DBMS TDBMS 1 Introduced in 1960s. Introduced in 1970s. 2 During introduction it followed the navigational modes (Navigational DBMS) for data storage and fetching. This model uses relationship between tables using primary keys, foreign keys . 3 Data fetching is slower for complex and large amount of data. Comparatively faster because of its relational model. 4 Used for applications using small amount of data. Used for complex and large amount of data. 5 Data Redundancy is common in this model Keys and indexes are used in the tables to avoid redundancy. 6 Example systems are dBase,, LibreOffice Base, FoxPro. Example systems are SQL Server, Oracle ,MS ACESS, MySQL, MariaDB, SQLite.
  • 4. The ANSI standard language for the definition and manipulation of relational database. Includes data definition language (DDL), statements that specify and modify database schemas. Includes a data manipulation language (DML), statements that manipulate database content. Structured Query Language (SQL)
  • 5. Some Facts on SQL SQL data is case-sensitive, SQL commands are not. First Version was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce. [SQL] Developed using Dr. E.F. Codd's paper, “A Relational Model of Data for Large Shared Data Banks.” SQL query includes references to tuples variables and the attributes of those variables
  • 6. SQL: DDL Commands CREATE TABLE: used to create a table. ALTER TABLE: modifies a table after it was created. DROP TABLE: removes a table from a database.
  • 7. SQL: CREATE TABLE Statement Things to consider before you create your table are: The type of data the table name what column(s) will make up the primary key the names of the columns CREATE TABLE statement syntax: CREATE TABLE <table name> ( field1 datatype ( NOT NULL ), field2 datatype ( NOT NULL ) );
  • 9. SQL: ALTER TABLE Statement To add or drop columns on existing tables. ALTER TABLE statement syntax: ALTER TABLE <table name> ADD attr datatype; or DROP COLUMN attr;
  • 10. SQL: DROP TABLE Statement DROP TABLE statement syntax: DROP TABLE <table name> ;
  • 11. Example: CREATE TABLE FoodCart ( date varchar(10), food varchar(20), profit float ); ALTER TABLE FoodCart ( ADD sold int ); ALTER TABLE FoodCart( DROP COLUMN profit ); DROP TABLE FoodCart; profit food date sold profit food date sold food date FoodCart FoodCart FoodCart
  • 12. SQL: DML Commands INSERT: adds new rows to a table. UPDATE: modifies one or more attributes. DELETE: deletes one or more rows from a table.
  • 13. SQL: INSERT Statement To insert a row into a table, it is necessary to have a value for each attribute, and order matters. INSERT statement syntax: INSERT into <table name> VALUES ('value1', 'value2', NULL); Example: INSERT into FoodCart VALUES (’02/26/08', ‘pizza', 70 ); FoodCart 70 pizza 02/26/08 500 hotdog 02/26/08 350 pizza 02/25/08 sold food date 500 hotdog 02/26/08 350 pizza 02/25/08 sold food date
  • 14. SQL: UPDATE Statement To update the content of the table: UPDATE statement syntax: UPDATE <table name> SET <attr> = <value> WHERE <selection condition>; Example: UPDATE FoodCart SET sold = 349 WHERE date = ’02/25/08’AND food = ‘pizza’; FoodCart 70 pizza 02/26/08 500 hotdog 02/26/08 350 pizza 02/25/08 sold food date 70 pizza 02/26/08 500 hotdog 02/26/08 349 pizza 02/25/08 sold food date
  • 15. SQL: DELETE Statement To delete rows from the table: DELETE statement syntax: DELETE FROM <table name> WHERE <condition>; Example: DELETE FROM FoodCart WHERE food = ‘hotdog’; FoodCart Note: If the WHERE clause is omitted all rows of data are deleted from the table. 70 pizza 02/26/08 500 hotdog 02/26/08 349 pizza 02/25/08 sold food date 70 pizza 02/26/08 349 pizza 02/25/08 sold food date
  • 16. SQL Statements, Operations, Clauses SQL Statements: Select SQL Operations: Join Left Join Right Join Like SQL Clauses: Order By Group By Having
  • 17. SQL: SELECT Statement A basic SELECT statement includes 3 clauses SELECT <attribute name> FROM <tables> WHERE <condition> SELECT Specifies the attributes that are part of the resulting relation FROM Specifies the tables that serve as the input to the statement WHERE Specifies the selection condition, including the join condition.
  • 18. Using a “*” in a select statement indicates that every attribute of the input table is to be selected. Example: SELECT * FROM … WHERE …; To get unique rows, type the keyword DISTINCT after SELECT. Example: SELECT DISTINCT * FROM … WHERE …; SQL: SELECT Statement (cont.)
  • 19. Example: Person 80 34 Peter 54 54 Helena 70 29 George 64 28 Sally 80 34 Harry Weight Age Name 80 34 Peter 54 54 Helena 80 34 Harry Weight Age Name 80 54 80 Weight 1) SELECT * FROM person WHERE age > 30; 2) SELECT weight FROM person WHERE age > 30; 3) SELECT distinct weight FROM person WHERE age > 30; 54 80 Weight
  • 20. SQL: Join operation A join can be specified in the FROM clause which list the two input relations and the WHERE clause which lists the join condition. Example: Biotech 1003 Sales 1002 IT 1001 Division ID TN 1002 MA 1001 CA 1000 State ID Emp Dept
  • 21. SQL: Join operation (cont.) Sales 1002 IT 1001 Dept.Division Dept.ID TN 1002 MA 1001 Emp.State Emp.ID inner join = join SELECT * FROM emp join dept (or FROM emp, dept) on emp.id = dept.id;
  • 22. SQL: Join operation (cont.) IT 1001 Sales 1002 null null Dept.Division Dept.ID CA 1000 TN 1002 MA 1001 Emp.State Emp.ID left outer join = left join SELECT * FROM emp left join dept on emp.id = dept.id;
  • 23. SQL: Join operation (cont.) Sales 1002 Biotech 1003 IT 1001 Dept.Division Dept.ID MA 1001 null null TN 1002 Emp.State Emp.ID right outer join = right join SELECT * FROM emp right join dept on emp.id = dept.id;
  • 24. SQL: Like operation Pattern matching selection % (arbitrary string) SELECT * FROM emp WHERE ID like ‘%01’; finds ID that ends with 01, e.g. 1001, 2001, etc _ (a single character) SELECT * FROM emp WHERE ID like ‘_01_’; finds ID that has the second and third character as 01, e.g. 1010, 1011, 1012, 1013, etc
  • 25. SQL: The ORDER BY Clause Ordered result selection desc (descending order) SELECT * FROM emp order by state desc puts state in descending order, e.g. TN, MA, CA asc (ascending order) SELECT * FROM emp order by id asc puts ID in ascending order, e.g. 1001, 1002, 1003
  • 26. SQL: The GROUP BY Clause The function to divide the tuples into groups and returns an aggregate for each group. Usually, it is an aggregate function’s companion SELECT food, sum(sold) as totalSold FROM FoodCart group by food; FoodCart 419 pizza 500 hotdog totalSold food 70 pizza 02/26/08 500 hotdog 02/26/08 349 pizza 02/25/08 sold food date
  • 27. SQL: The HAVING Clause The substitute of WHERE for aggregate functions Usually, it is an aggregate function’s companion SELECT food, sum(sold) as totalSold FROM FoodCart group by food having sum(sold) > 450; FoodCart 500 hotdog totalSold food 70 pizza 02/26/08 500 hotdog 02/26/08 349 pizza 02/25/08 sold food date
  • 28. SQL: Aggregate Functions Are used to provide summarization information for SQL statements, which return a single value. COUNT(attr) SUM(attr) MAX(attr) MIN(attr) AVG(attr) Note: when using aggregate functions, NULL values are not considered, except in COUNT(*) .
  • 29. SQL: Aggregate Functions (cont.) COUNT(attr) -> return # of rows that are not null Ex: COUNT(distinct food) from FoodCart; -> 2 SUM(attr) -> return the sum of values in the attr Ex: SUM(sold) from FoodCart; -> 919 MAX(attr) -> return the highest value from the attr Ex: MAX(sold) from FoodCart; -> 500 70 pizza 02/26/08 500 hotdog 02/26/08 349 pizza 02/25/08 sold food date FoodCart
  • 30. SQL: Aggregate Functions (cont.) MIN(attr) -> return the lowest value from the attr Ex: MIN(sold) from FoodCart; -> 70 AVG(attr) -> return the average value from the attr Ex: AVG(sold) from FoodCart; -> 306.33 Note: value is rounded to the precision of the datatype 70 pizza 02/26/08 500 hotdog 02/26/08 349 pizza 02/25/08 sold food date FoodCart