Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL and Relational Algebra Edel Sherratt Nigel Hardy Horst Holstein.

Similar presentations


Presentation on theme: "SQL and Relational Algebra Edel Sherratt Nigel Hardy Horst Holstein."— Presentation transcript:

1 SQL and Relational Algebra Edel Sherratt Nigel Hardy Horst Holstein

2 SQL DML and DDL DML – data manipulation language SELECT UPDATE DELETE INSERT INTO DDL – data definition language CREATE ALTER DROP

3 Relational Closure The output of a relational operation in relational algebra is a relation The output of an SQL query or update statement is a table

4 Recall Relational Algebra Project Removes “columns” (attributes) Written as: A [X, Y] returns a relation with two named attributes Duplicate tuples eliminated if the lost attributes distinguished them All attributes named - identity projection No attributes named - nullary projection

5 SQL SELECT as Projection SELECT A,B FROM T Selects columns from the table T Compare with relational algebra Project T[A,B]

6 SELECT as Projection SELECT * FROM T Selects all the columns from T Identity projection T[all attributes of T named]

7 SELECT as Projection But SELECT can deliver duplicates Unlike relational algebra Project Use SELECT DISTINCT to avoid duplicates

8 Relational Algebra Restrict Based on: one relation scalar operator Θ Θ could be, >=, > etc. two attributes Often represented by the word where One attribute can be replaced by an expression Examples A where X Θ Y B where r > s C where length < 42 Selects tuples Removes rows

9 RESTRICT people WHERE job = ‘Sales Rep’ RETURNS

10 SQL SELECT as Restriction SQL: SELECT * from People WHERE job = 'Sales Rep' Relational Algebra: People WHERE job = 'Sales Rep'

11 SQL operators in the WHERE clause SQL allows these operators =, <> (equal, not equal; sometimes != is used instead of <>) (less than, greater than) = (at most, at least) BETWEEN (inclusive range) LIKE (a pattern) IN (set of values for a column) AND, OR


Download ppt "SQL and Relational Algebra Edel Sherratt Nigel Hardy Horst Holstein."

Similar presentations


Ads by Google