SlideShare une entreprise Scribd 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

Contenu connexe

Tendances

Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
Nargis Ehsan
 
Hash table
Hash tableHash table
Hash table
Vu Tran
 
Data definition language
Data definition languageData definition language
Data definition language
VENNILAV6
 
Database Languages.pptx
Database Languages.pptxDatabase Languages.pptx
Database Languages.pptx
MuhammadFarhan858304
 
Triggers
TriggersTriggers
Triggers
Pooja Dixit
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
Anusha sivakumar
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
kuldeep100
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
Quang Minh Đoàn
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
Estiak Khan
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
DBMS: Types of keys
DBMS:  Types of keysDBMS:  Types of keys
DBMS: Types of keys
Bharati Ugale
 
Database language
Database languageDatabase language
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
VENNILAV6
 
Theory of Computation Unit 1
Theory of Computation Unit 1Theory of Computation Unit 1
Theory of Computation Unit 1
Jena Catherine Bel D
 
Mapping Cardinalities
Mapping CardinalitiesMapping Cardinalities
Mapping Cardinalities
Megha Sharma
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
Sharad Dubey
 
join relation.pptx
join relation.pptxjoin relation.pptx
join relation.pptx
Anusha sivakumar
 
Association rules apriori algorithm
Association rules   apriori algorithmAssociation rules   apriori algorithm
Association rules apriori algorithm
Dr. Jasmine Beulah Gnanadurai
 
14. Query Optimization in DBMS
14. Query Optimization in DBMS14. Query Optimization in DBMS
14. Query Optimization in DBMS
koolkampus
 

Tendances (20)

Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
 
Hash table
Hash tableHash table
Hash table
 
Data definition language
Data definition languageData definition language
Data definition language
 
Database Languages.pptx
Database Languages.pptxDatabase Languages.pptx
Database Languages.pptx
 
Triggers
TriggersTriggers
Triggers
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
DBMS: Types of keys
DBMS:  Types of keysDBMS:  Types of keys
DBMS: Types of keys
 
Database language
Database languageDatabase language
Database language
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Theory of Computation Unit 1
Theory of Computation Unit 1Theory of Computation Unit 1
Theory of Computation Unit 1
 
Mapping Cardinalities
Mapping CardinalitiesMapping Cardinalities
Mapping Cardinalities
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
join relation.pptx
join relation.pptxjoin relation.pptx
join relation.pptx
 
Association rules apriori algorithm
Association rules   apriori algorithmAssociation rules   apriori algorithm
Association rules apriori algorithm
 
14. Query Optimization in DBMS
14. Query Optimization in DBMS14. Query Optimization in DBMS
14. Query Optimization in DBMS
 

Similaire à 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 new
SANTOSH 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 commands
Belle 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
 
Query
QueryQuery
Sql
SqlSql
Sql
SqlSql
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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 

Dernier (20)

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 

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