Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

19
SQL Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León

Transcript of Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

Page 1: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

SQL

Seminar Programmiersprachen – FG Praktische Informatik

Pablo Pinés León

Page 2: 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

Page 3: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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

Page 4: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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

Page 5: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

Name changed

New facilities: Join, having

Null values, three-value logic

New predicates: Like

o Pragmatic decisions

Evolution of System R

Page 6: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

DML - Data Manipulation Language◦ Insert, Merge, etc◦ Transactions

DDL – Data Definition Language◦ Create, Drop, etc

Subsets

Page 7: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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

Page 8: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

Biographies

Page 9: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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

Page 10: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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

Page 11: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

Interview

Page 12: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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”

Page 13: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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

Page 14: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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”

Page 15: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

Simplicity

Extensibility

Abstraction (data independence in DB)

Optimizability: where possible, the semantic specification should be declarative

Resilience

Design principles

Page 16: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

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”

Page 17: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

SQL injection attacks

Now it’s an object-relational language◦ User-defined types and methods

They expected “casual users” to use it

Unexpected evolution

Page 18: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

Any questions?

Page 19: Seminar Programmiersprachen – FG Praktische Informatik Pablo Pinés León.

Thank you!