Copyright © Curt Hill SQL The Intergalactic Standard Database Query Language
What is it? Abbreviation of Structured Query Language Official pronunciation is spelled out S – Q – L Official as in from ISO/ANSI Often pronounced See-Quell Both work in this class Copyright © Curt Hill
Why SQL? A major strength of the relational model: supports simple, powerfulqueryingof data. Queries can be written intuitively, and the DBMS is responsible for efficient evaluation. – Precise semantics for relational queries. – Allows the optimizer to extensively re- order operations – Provided the answer does not change.
SQL – a requirement? A database does not need to offer SQL interpretation to be a classified as relational Commercially it is mostly a requirement Notice the names of some: –SQL-Server –MySql Copyright © Curt Hill
History Developed by IBM in system R –1974 – 1977 –Originally called SEQUEL for Structured English QUEry Language Used in some variation by all major relational DBs Standards: – SQL-86 – SQL-89 (minor revision) – SQL-92 (major revision) AKA SQL2 – SQL-1999 (major extensions) AKA SQL3 – SQL-2003 – SQL-2006 – SQL-2008
Standard? SQL is one of the least standardized common languages Why? Queries are specific to a single database –They must take into account table names and field names –Organizations have databases that contain data peculiar to them –Even similar databases will vary with regard to table and field names Copyright © Curt Hill
Variants It seems that each major database has its variants Accepts the basic language but: –Leaves out some pieces –Adds proprietary extensions We will try to examine the variations of the three major ones: –Oracle 10 –SQL Server –MySQL Copyright © Curt Hill
ODBC Online Data Base Connectivity Take commands from program Connect to a SQL based DB on the net ODBC handles two aspects: –The TCP/IP connection –Converting their SQL to the variant handled by this particular database and the format of the returned data JDBC –Java interface to ODBC Copyright © Curt Hill
Parts of the language Data Manipulation Language (DML) –This subset was influenced by the relational algebra and relational calculus –Gives us facility to: Generate queries Insert records Delete records Modify records Data Definition Language (DDL) –Used to define, update and delete databases, tables and views
Copyright © Curt Hill Faculty load query (calculus) Consider a sample query from the calculus { | naid,dp,dg,ar,title( Faculty) Course Faculty_Teach )}
Copyright © Curt Hill Faculty load query (SQL) Select f.name, c.dept, c.number, c.crhr From faculty as f, course as c, faculty_teach as ft Where f.naid=ft.naid AND ft.dept = c.dept AND ft.number = c.number Select is algebra or calculus From is set membership (calculus) Where is the implied equalities (calculus)