Post on 12-Jan-2016
SQL
Seminar Programmiersprachen – FG Praktische Informatik
Pablo Pinés León
SQL is a language for managing data in RDBMS
SQL stands for Structured Query Language
Originally called SEQUEL
Based on Edgar Codd’s Relational Model, which had attracted a lot of attention at that time
Currently widely used
First experimental implementation: System R, by IBM
First commercial implementation: Oracle
Introduction
Language based on common english, easy to write, based in tables
Procedural, but avoiding some mathematical concepts
High level querying concepts, as grouping
Initial objectives of design
More functionality: data management not relying solely on database administrators
It should serve both as query language and as a development language
Unique opportunity: free from backward compatibility
Initial objectives of design
Name changed
New facilities: Join, having
Null values, three-value logic
New predicates: Like
o Pragmatic decisions
Evolution of System R
DML - Data Manipulation Language◦ Insert, Merge, etc◦ Transactions
DDL – Data Definition Language◦ Create, Drop, etc
Subsets
SELECT
CASE (bottlecount)
WHEN 0 THEN 'No more bottle of beer on the wall, no more bottles of beer. ' ||
'Go to the store and buy some more, 99 bottles of beer on the wall.'
WHEN 1 THEN '1 bottle of beer on the wall, 1 bottle of beer. ' ||
'Take one down and pass it around, no more bottles of beer on the wall.'
WHEN 2 THEN '2 bottles of beer on the wall, 2 bottles of beer. ' ||
'Take one down and pass it around, 1 bottle of beer on the wall.'
ELSE
rtrim (cast((BottleCount) as char(2))) || ' bottles of beer on the wall, ' ||
rtrim (cast((BottleCount) as char(2))) || ' bottles of beer. ' ||
'Take one down and pass it around, ' ||
rtrim (cast((BottleCount)-1 as char(2))) || ' bottles of beer on the wall.'
END
FROM
(
SELECT avalue * 10 + bvalue as bottlecount
FROM
(VALUES (9), (8), (7), (6), (5), (4), (3), (2), (1), (0)) a(avalue),
(VALUES (9), (8), (7), (6), (5), (4), (3), (2), (1), (0)) b(bvalue)
) as valuelist;
99 bottles of beer
Biographies
Born in 1944 in San José, USA
M.Sc and PhD in electrical engineering by Stanford University. Minored in computer science
Worked for IBM Research, last years in Almaden
XQuery
He was awarded by the ACM in 1988
Don Chamberlin
Born in 1947 in New York
PhD in Computer Science at Purdue
Worked in Yorktown Heights for IBM => Boyce-Codd Normal Form
He moved to San Jose to work with Don Chamberlain
Died of brain aneurysm in 1974
Ray Boyce
Interview
Important for any language: Well defined data model (though you can retrofit it later)
SQL is declarative:◦ Optimizability◦ Data independence◦ High level is easier
Basis
“There was significant uncertainty about whether a
declarative language as complex as SQL could be implemented
with the degree of performance required for commercial
applications”
Consistency is a must
Definition of ACID properties for transactions (atomicity, consistency, isolation, durability)
Degrees of isolation (the higher the isolation is, the bigger portion it might lock up)
Sidenote: halloween problem
Concurrency in shared data
Not all of them were well observed in SQL
Closure Completeness Orthogonality: concepts defined
independently and avoiding special rules◦ A expression that returns a certain type should be
allows to be used in any context where that data type is expected
Consistency
Design principles
“I think the history of SQL illustrates the importance of having a specific set of principles that guide the process of
language design”
Simplicity
Extensibility
Abstraction (data independence in DB)
Optimizability: where possible, the semantic specification should be declarative
Resilience
Design principles
Database administration tasks
Quite easy to learn
Various implementations
Interfaces with popular programming languages
ANSI and ISO standards
Propitious time
Reasons for its sucess
“I think that the main reason for the popularity of SQL derives from the power and simplicity of Ted Codd’s
relational data model”
SQL injection attacks
Now it’s an object-relational language◦ User-defined types and methods
They expected “casual users” to use it
Unexpected evolution
Any questions?
Thank you!