



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of sql (structured query language), its history, and the basic concepts of sql queries. It covers range-restricted queries, sql syntax, data types, and the use of correlation names. The document also includes examples and explanations of the 'select', 'from', and 'where' clauses.
Typology: Slides
1 / 35
This page cannot be seen from the preview
Don't miss anything!




























David Toman
School of Computer Science University of Waterloo
Introduction to Databases CS
Three major parts of the language: 1 DML (Data Manipulation Language) ) Query language ) Update language 2 DDL (Data Definition Language) ) defines schema for relations ) creates (modifies/destroys) database objects. 3 DCL (Data Control Language) ) access control
Also: Embedded SQL (SQL/J) and ODBC (JDBC) ) necessary for application development
author(aid integer, name char(20)) wrote(author integer, publication char(8)) publication(pubid char(8), title char(70)) book(pubid char(8), publisher char(50), year integer) journal(pubid char(8), volume integer, no integer, year integer) proceedings(pubid char(8), year integer) article(pubid char(8), crossref char(8), startpage integer, endpage integer)
... SQL is NOT case sensitive.
Basic syntax:
SELECT DISTINCT
9 p; x ; y:publication(p; n) ^ book(p; x ; y)
) we prefix the ambiguous attributes names by the name of the appropriate relation:
List titles of all books:
SQL> select distinct title 2 from publication, book 3 where publication.pubid=book.pubid;
Logics for Databases and Information Systems
List all publications with at least two authors:
SQL> select distinct r1.publication 2 from wrote r1, wrote r 3 where r1.publication=r2.publication 4 and r1.author!=r2.author;
ChSa ChTo ChTo98a
Syntax: FROM R 1 [ n 1 ]; : : : ; Rk [ nk ]
we can create values in the answer tuples using built-in functions:
Note: all attribute names MUST be “present” in the FROM clause.
For every article list the number of pages: SQL> select pubid, endpage-startpage+ 2 from article;
PUBID ENDPAGE-STARTPAGE+
ChTo98 40 ChTo98a 28 Tom97 19
and name the resulting attributes id,numberofpages: SQL> select pubid as id, 2 endpage-startpage+1 as numberofpages 3 from article;
ID NUMBEROFPAGES
ChTo98 40 ChTo98a 28 Tom97 19
Additional conditions on tuples that qualify for the answer.
WHERE C