SlideShare a Scribd company logo
1 of 28
1
Structured Query Language
(SQL)
2
Structured Query Language
• SQL consists of a set of commands for defining,
accessing, and managing relational databases.
• In 1970, E.F. Codd at IBM Research Labs in San
Jose, California published “A Relational Model of
Data for Large Shared Data Banks”
(Communications of the ACM, Vol. 13, No. 6,
June 1970) in which he described a set of abstract
principles for database management - the
relational model. The field of relational database
technology has its origins in that paper.
3
Structured Query Language
• This research described several relational
languages which implement some/all of the
features of the abstract relational model.
One of these languages which was created
in 1974-75 was the “Structured English
Query Language” (SEQUEL), defined by
Donald Chamberlin and others at IBM
Labs. The first IBM prototype was called
SEQUEL-XRM (1974-75).
4
Structured Query Language
• A revised version of SEQUEL-XRM was defined
in 1976-77 and named SEQUEL/Z. The name
was changed to SQL for legal reasons.
• A prototype of this became operational in 1977
called System R.
• Due to the success of System R, vendors rushed to
create their own SQL products. The Oracle
database was released before IBM's own product.
5
Structured Query Language
• In 1982, the American National Standards
Institute (ANSI) chartered its Database Committee
(X3H2) to develop a standard for a relational
language. In 1986, the X3H2 proposal was
ratified by ANSI which consisted essentially of
the IBM dialect of SQL.
• In 1987, the ANSI standard was accepted as an
international standard by the International
Organization for Standards (ISO).
6
Structured Query Language
• The original standard is also known as SQL/86.
• Enhancements were made over time
– SQL/89 - included an Integrity Enhancement Feature
– SQL/92 - ISO and ANSI developed a revised standard
also known as SQL2
– SQL/99 - “SQL3” incorporates object-oriented access
– A consortium of vendors known as the SQL Access
Group has been working to enhance interoperability
across different systems
7
SQL as a Standard
• Since SQL is such a pervasive standard, let
us review some information on standards -
their good points and their not so good
points.
8
Are Standards Good? -- Good
Points
• Standards reduce training costs.
• They promote application portability.
• Standards promote application longevity.
– Standards have a reasonably long life, so
applications using them should as well.
9
Are Standards Good? -- Good
Points
• Intersystem Communications
– are more easily achieved.
– Different database management systems can function
equally well on a single database if they support the
same standard interface.
• Customer Choice
– If products support the same interface then customers
can focus on the implementation that best meets their
own needs without having to choose among different
interfaces.
10
Are Standards Good? -- Bad
Points
• Standards can stifle creativity - system
implementers may be prevented from
providing “the best” solution because the
standard prescribes some alternative.
• SQL has some flaws in its design, some of
which are considered severe.
11
SQL Overview
• SQL is used to define, manipulate, and
control data in relational databases.
• A relational database is one which is
perceived as a collection of tables by the
user.
• A table is an unordered collection of rows.
12
A Suppliers-and-Part Database
Example
• Tables
– S : suppliers
– P : parts (and where to ship an order)
– SP : shipment of parts by suppliers
13
Table S
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
SNO SNAME STATUS CITY
Primary Key = SNO
14
Table P
P1 Nut Red 12 London
P2 Bolt Green 17 Paris
P3 Screw Blue 17 Rome
P4 Screw Red 14 London
PNO PNAME COLOUR WEIGHT CITY
Primary Key = PNO
15
Table SP
S1 P1 300
S1 P2 200
S2 P1 300
S3 P2 200
S4 P4 400
SNO PNO QTY
Primary Key = SNO and PNO
16
Tables
• Tables can be thought of as files, with rows
representing records and the columns as fields.
• The SQL standard always uses the terms table,
row and column.
• SQL statements can be invoked either
interactively or from within an application.
– Interactive SQL generally displays the results on the
screen.
– Invocation from a program means the results are made
available as input to the program.
17
Creating Tables
• Empty tables are constructed using the
CREATE TABLE statement.
• Data must be entered later using INSERT.
CREATE TABLE S ( SNO CHAR(5),
SNAME CHAR(20),
STATUS DECIMAL(3),
CITY CHAR(15),
PRIMARY KEY (SNO) )
18
Creating Tables
• A table name and unique column names
must be specified.
• Columns which are defined as primary keys
will never have two rows with the same key
value.
• Primary key may consist of more than one
column (values unique in combination)
called composite key.
19
Creating Tables
CREATE TABLE SP ( SNO CHAR(5),
PNO CHAR(5),
QTY DECIMAL(5),
PRIMARY KEY (SNO,PNO),
FOREIGN KEY (SNO) REFERENCES S,
FOREIGN KEY (PNO) REFERENCES P )
• Foreign keys refer to other tables.
– Any key in SP.SNO must also appear in S.SNO and
any key in SP.PNO must appear in P.PNO - a shipment
cannot exist unless the supplier and part also exist.
20
Data Manipulation
• There are four basic SQL data manipulation
operations.
– SELECT - retrieves data
– INSERT - add a new row
– UPDATE - change values in existing records
– DELETE - remove row(s)
21
The Select Statement
• SQL Query:
SELECT S.CITY
FROM S
WHERE S.SNO = 'S4'
• Result:
CITY
-------
London
22
SELECT
• SELECT is used for data retrieval.
• FROM indicates the table from which to retrieve
the data.
• WHERE is used to describe column features that
are desired in the retrieved data.
– No WHERE statement will cause all rows to be
returned.
– You can use all of the standard comparisons
(<,<=,>,>=,=).
– Literal strings must appear in single quotes.
23
INSERT
INSERT
INTO SP ( SNO, PNO, QTY )
VALUES ( 'S4', 'P1', 1000 )
• Row added to Table SP.
24
UPDATE
UPDATE S
SET STATUS = 2 * S.STATUS
WHERE S.CITY = 'London'
• Status doubled for suppliers in London (S1
and S4)
25
DELETE
DELETE
FROM P
WHERE P.WEIGHT > 15
• Rows deleted from P where WEIGHT > 15
(P2 and P3)
26
SELECT
• SELECT has the general form
SELECT-FROM-WHERE.
• The result is another (new) table.
27
SELECT
SELECT DISTINCT
P.COLOUR, P.CITY
FROM P
WHERE P.WEIGHT > 10
AND P.CITY <> 'Paris'
results in the table,
COLOUR CITY
----------------
Red London
Blue Rome
[ Red London ] - eliminated
because of
DISTINCT
statement which
removes multiple copies of rows
28
SELECT
• DISTINCT - no duplicate rows.
• No WHERE - all rows of FROM table are
returned.
• SELECT * is short for select the entire row
(all columns).

More Related Content

Viewers also liked

1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - IntroductionVarun A M
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Eddyzulham Mahluzydde
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introductionSmriti Jain
 
Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3Eddyzulham Mahluzydde
 
Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Eddyzulham Mahluzydde
 
Concept of Structured Query Language (SQL) in SQL server as well as MySql. BB...
Concept of Structured Query Language (SQL) in SQL server as well as MySql. BB...Concept of Structured Query Language (SQL) in SQL server as well as MySql. BB...
Concept of Structured Query Language (SQL) in SQL server as well as MySql. BB...Rohan Byanjankar
 
Mysql Introduction
Mysql IntroductionMysql Introduction
Mysql Introductionhemant meena
 
Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Languagepandey3045_bit
 
BITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLEhsan Hamzei
 
Chapter 5 Database Transaction Management
Chapter 5 Database Transaction ManagementChapter 5 Database Transaction Management
Chapter 5 Database Transaction ManagementEddyzulham Mahluzydde
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
Chapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemChapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemEddyzulham Mahluzydde
 

Viewers also liked (14)

1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3
 
Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Concept of Structured Query Language (SQL) in SQL server as well as MySql. BB...
Concept of Structured Query Language (SQL) in SQL server as well as MySql. BB...Concept of Structured Query Language (SQL) in SQL server as well as MySql. BB...
Concept of Structured Query Language (SQL) in SQL server as well as MySql. BB...
 
Mysql Introduction
Mysql IntroductionMysql Introduction
Mysql Introduction
 
Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Language
 
BITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQL
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Chapter 5 Database Transaction Management
Chapter 5 Database Transaction ManagementChapter 5 Database Transaction Management
Chapter 5 Database Transaction Management
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Chapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemChapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management System
 

Similar to Structured query language

NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfcookie1969
 
122 sql for-beginners
122 sql for-beginners122 sql for-beginners
122 sql for-beginnerssuzzanj1990
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsNirav Shah
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsTeamstudio
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343Edgar Alejandro Villegas
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13AnusAhmad
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introductionadryanbub
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
SQL Queries
SQL QueriesSQL Queries
SQL QueriesNilt1234
 
Dan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesDan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesEmbarcadero Technologies
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statementsxKinAnx
 
Les13[1]Other Database Objects
Les13[1]Other Database ObjectsLes13[1]Other Database Objects
Les13[1]Other Database Objectssiavosh kaviani
 

Similar to Structured query language (20)

NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
 
122 sql for-beginners
122 sql for-beginners122 sql for-beginners
122 sql for-beginners
 
Database part2-
Database part2-Database part2-
Database part2-
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13
 
Reviewing SQL Concepts
Reviewing SQL ConceptsReviewing SQL Concepts
Reviewing SQL Concepts
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introduction
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Dan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesDan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New Features
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statements
 
Sap example
Sap exampleSap example
Sap example
 
Les13[1]Other Database Objects
Les13[1]Other Database ObjectsLes13[1]Other Database Objects
Les13[1]Other Database Objects
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
DBMS Chapter-3.ppsx
DBMS Chapter-3.ppsxDBMS Chapter-3.ppsx
DBMS Chapter-3.ppsx
 
SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
 

More from Neeti Gupta

Social cost benefit analysis
Social cost benefit analysisSocial cost benefit analysis
Social cost benefit analysisNeeti Gupta
 
Housing+finance,+vc,+mb,+cc
Housing+finance,+vc,+mb,+ccHousing+finance,+vc,+mb,+cc
Housing+finance,+vc,+mb,+ccNeeti Gupta
 
Structured query language
Structured query languageStructured query language
Structured query languageNeeti Gupta
 

More from Neeti Gupta (7)

Social cost benefit analysis
Social cost benefit analysisSocial cost benefit analysis
Social cost benefit analysis
 
Housing+finance,+vc,+mb,+cc
Housing+finance,+vc,+mb,+ccHousing+finance,+vc,+mb,+cc
Housing+finance,+vc,+mb,+cc
 
Structured query language
Structured query languageStructured query language
Structured query language
 
Business dining
Business diningBusiness dining
Business dining
 
Business dining
Business diningBusiness dining
Business dining
 
Business dining
Business diningBusiness dining
Business dining
 
Business dining
Business diningBusiness dining
Business dining
 

Recently uploaded

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Structured query language

  • 2. 2 Structured Query Language • SQL consists of a set of commands for defining, accessing, and managing relational databases. • In 1970, E.F. Codd at IBM Research Labs in San Jose, California published “A Relational Model of Data for Large Shared Data Banks” (Communications of the ACM, Vol. 13, No. 6, June 1970) in which he described a set of abstract principles for database management - the relational model. The field of relational database technology has its origins in that paper.
  • 3. 3 Structured Query Language • This research described several relational languages which implement some/all of the features of the abstract relational model. One of these languages which was created in 1974-75 was the “Structured English Query Language” (SEQUEL), defined by Donald Chamberlin and others at IBM Labs. The first IBM prototype was called SEQUEL-XRM (1974-75).
  • 4. 4 Structured Query Language • A revised version of SEQUEL-XRM was defined in 1976-77 and named SEQUEL/Z. The name was changed to SQL for legal reasons. • A prototype of this became operational in 1977 called System R. • Due to the success of System R, vendors rushed to create their own SQL products. The Oracle database was released before IBM's own product.
  • 5. 5 Structured Query Language • In 1982, the American National Standards Institute (ANSI) chartered its Database Committee (X3H2) to develop a standard for a relational language. In 1986, the X3H2 proposal was ratified by ANSI which consisted essentially of the IBM dialect of SQL. • In 1987, the ANSI standard was accepted as an international standard by the International Organization for Standards (ISO).
  • 6. 6 Structured Query Language • The original standard is also known as SQL/86. • Enhancements were made over time – SQL/89 - included an Integrity Enhancement Feature – SQL/92 - ISO and ANSI developed a revised standard also known as SQL2 – SQL/99 - “SQL3” incorporates object-oriented access – A consortium of vendors known as the SQL Access Group has been working to enhance interoperability across different systems
  • 7. 7 SQL as a Standard • Since SQL is such a pervasive standard, let us review some information on standards - their good points and their not so good points.
  • 8. 8 Are Standards Good? -- Good Points • Standards reduce training costs. • They promote application portability. • Standards promote application longevity. – Standards have a reasonably long life, so applications using them should as well.
  • 9. 9 Are Standards Good? -- Good Points • Intersystem Communications – are more easily achieved. – Different database management systems can function equally well on a single database if they support the same standard interface. • Customer Choice – If products support the same interface then customers can focus on the implementation that best meets their own needs without having to choose among different interfaces.
  • 10. 10 Are Standards Good? -- Bad Points • Standards can stifle creativity - system implementers may be prevented from providing “the best” solution because the standard prescribes some alternative. • SQL has some flaws in its design, some of which are considered severe.
  • 11. 11 SQL Overview • SQL is used to define, manipulate, and control data in relational databases. • A relational database is one which is perceived as a collection of tables by the user. • A table is an unordered collection of rows.
  • 12. 12 A Suppliers-and-Part Database Example • Tables – S : suppliers – P : parts (and where to ship an order) – SP : shipment of parts by suppliers
  • 13. 13 Table S S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London SNO SNAME STATUS CITY Primary Key = SNO
  • 14. 14 Table P P1 Nut Red 12 London P2 Bolt Green 17 Paris P3 Screw Blue 17 Rome P4 Screw Red 14 London PNO PNAME COLOUR WEIGHT CITY Primary Key = PNO
  • 15. 15 Table SP S1 P1 300 S1 P2 200 S2 P1 300 S3 P2 200 S4 P4 400 SNO PNO QTY Primary Key = SNO and PNO
  • 16. 16 Tables • Tables can be thought of as files, with rows representing records and the columns as fields. • The SQL standard always uses the terms table, row and column. • SQL statements can be invoked either interactively or from within an application. – Interactive SQL generally displays the results on the screen. – Invocation from a program means the results are made available as input to the program.
  • 17. 17 Creating Tables • Empty tables are constructed using the CREATE TABLE statement. • Data must be entered later using INSERT. CREATE TABLE S ( SNO CHAR(5), SNAME CHAR(20), STATUS DECIMAL(3), CITY CHAR(15), PRIMARY KEY (SNO) )
  • 18. 18 Creating Tables • A table name and unique column names must be specified. • Columns which are defined as primary keys will never have two rows with the same key value. • Primary key may consist of more than one column (values unique in combination) called composite key.
  • 19. 19 Creating Tables CREATE TABLE SP ( SNO CHAR(5), PNO CHAR(5), QTY DECIMAL(5), PRIMARY KEY (SNO,PNO), FOREIGN KEY (SNO) REFERENCES S, FOREIGN KEY (PNO) REFERENCES P ) • Foreign keys refer to other tables. – Any key in SP.SNO must also appear in S.SNO and any key in SP.PNO must appear in P.PNO - a shipment cannot exist unless the supplier and part also exist.
  • 20. 20 Data Manipulation • There are four basic SQL data manipulation operations. – SELECT - retrieves data – INSERT - add a new row – UPDATE - change values in existing records – DELETE - remove row(s)
  • 21. 21 The Select Statement • SQL Query: SELECT S.CITY FROM S WHERE S.SNO = 'S4' • Result: CITY ------- London
  • 22. 22 SELECT • SELECT is used for data retrieval. • FROM indicates the table from which to retrieve the data. • WHERE is used to describe column features that are desired in the retrieved data. – No WHERE statement will cause all rows to be returned. – You can use all of the standard comparisons (<,<=,>,>=,=). – Literal strings must appear in single quotes.
  • 23. 23 INSERT INSERT INTO SP ( SNO, PNO, QTY ) VALUES ( 'S4', 'P1', 1000 ) • Row added to Table SP.
  • 24. 24 UPDATE UPDATE S SET STATUS = 2 * S.STATUS WHERE S.CITY = 'London' • Status doubled for suppliers in London (S1 and S4)
  • 25. 25 DELETE DELETE FROM P WHERE P.WEIGHT > 15 • Rows deleted from P where WEIGHT > 15 (P2 and P3)
  • 26. 26 SELECT • SELECT has the general form SELECT-FROM-WHERE. • The result is another (new) table.
  • 27. 27 SELECT SELECT DISTINCT P.COLOUR, P.CITY FROM P WHERE P.WEIGHT > 10 AND P.CITY <> 'Paris' results in the table, COLOUR CITY ---------------- Red London Blue Rome [ Red London ] - eliminated because of DISTINCT statement which removes multiple copies of rows
  • 28. 28 SELECT • DISTINCT - no duplicate rows. • No WHERE - all rows of FROM table are returned. • SELECT * is short for select the entire row (all columns).