Download presentation
Presentation is loading. Please wait.
Published byEugene Morris Modified over 9 years ago
1
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 17 A First Course in Database Systems
2
Relational Calculus Query:Find the names of employees who have no dependents. Query(DRC): {qs| t ) EMPLOYEE(qrstuvwxyz) and (not ( l ) (DEPENDENT(lmnop) and t = l)))} The above query can be restated using universal ( ) quantifiers instead of the existential( ) quantifiers as follows: Query(DRC): {qs| t ) EMPLOYEE(qrstuvwxyz) and (( l ) not (DEPENDENT(lmnop) or not t = l)))}
3
Relational Calculus (not ( l ) (DEPENDENT(lmnop) and t = l) ==> (( l ) not (DEPENDENT(lmnop) or not t = l) because not ( l ) not (DEPENDENT(lmnop) not and not t=l) = (( l ) not (DEPENDENT(lmnop) or not t = l)
4
SQL The most commonly used relational DBMS’s query and modify the database through a language called SQL (sometimes pronounced “sequel”) SQL “Structured Query Language” Relational Algebra is considered to be too technical for most DBMS users !! Why? A query in relational algebra is written as a sequence of operations.
5
SQL In relational algebra users are required to specify HOW I.e What Order (Procedural) SQL provides a high-level (declarative) interface, so users only specify WHAT the result is to be. Leaving the actual optimization and decision on HOW to execute the query to the DBMS through SQL!
6
SQL There are many different dialects of SQL: SQL-92 (SQL2) SQL3 etc.
7
SQL SQL Syntax: CREATE TABLE ( [NOT NULL] {, [NOT NULL]}) DROP TABLE. DROP VIEW
8
SQL The SQL DDL allows the specifications of not only a set of relations but also informaition about each relation, including: -the schema for each relation -the domain of values associated with each attribute -the set of indicies to be maintained for each relation -security and authorization information for each relation -integrity constraints
9
SQL An SQL relation is defined using the create table command: create table r (A 1 D 1, A 2 D 2, ……….., A n D n ) r name of raltion A i name of an attribute in the schema of relation r D i the data type of values in the domain of attribute A i
10
SQL A newly created table (relation) is empty initially The insert command can be used to load data into the relation To remove a relation from an SQL database, we use the drop table command
11
SQL The drop table command deletes all information about the dropped relation from the database drop table r is a more drastic action than delete r drop table r deletes not only all tuples of r but also delete the schema for r NOTE: after r is dropped, no tuples can be inserted into r unless it is re-created using the create table command
12
The Database Language SQL The alter table command is used to add attributes to an existing to an existing relation -All tuples in the relation are assigned null as the value for the new attribute alter table r add A D r name of existing relation A name of attribute to be added D domain of the added attribute NOTE: alter is not in the SQL standard
13
SQL Language Basic SQL Queries and Structure: SQL queries are formed from three clauses SELECT FROM WHERE list of attribute names whose values are to be retrieved by the query
14
SQL Language Basic SQL Queries and Structure: SQL queries are formed from three clauses SELECT FROM WHERE a list of relation names required to process the query conditional (Boolean) search expression identifying the tuples to be retrieved by the query
15
SQL SELECT clause corresponds to the projection operation of the relational algebra FROM clause corresponds to the Cartesian Product operation of the relational algebra WHERE clause corresponds to the selection predicate of the relation algebra
16
SQL NOTE: The different meaning or roles of the term “select” in SQL and the relational algebra is an unfortunate historical fact!
17
SQL A typical SQL query has the form: select A 1, A 2, …….A n from r 1, r 2,……….r m whereP A1, A2, …….An ( P (r 1 r 2 ………. r m )) Relational Algebra
18
SQL A typical SQL query has the form: select A 1, A 2, …….A n from r 1, r 2,……….r m whereP If the where clause is omitted, the predicate P is TRUE The list A 1, A 2, …….A n may be replaced with a star (*) to select all attributes of all relations appearing in the from clause
19
SQL A typical SQL query has the form: select A 1, A 2, …….A n from r 1, r 2,……….r m whereP - forms a Cartesian product of the relations named in the from clause - performs a relational algebra selection using the where clause predicate - and then projects the result onto the attributes of the select clause
20
SQL A typical SQL query has the form: select A 1, A 2, …….A n from r 1, r 2,……….r m whereP The result of the above SQL query is a relation
21
SQL Next Lecture MORE SQL
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.