Presentation is loading. Please wait.

Presentation is loading. Please wait.

Foundations of Relational Implementation zImplementing Relational Databases zRelational Data Manipulation zRelational Algebra.

Similar presentations


Presentation on theme: "Foundations of Relational Implementation zImplementing Relational Databases zRelational Data Manipulation zRelational Algebra."— Presentation transcript:

1 Foundations of Relational Implementation zImplementing Relational Databases zRelational Data Manipulation zRelational Algebra

2 Definitions zRelation structure = table format zOccurrence = structure + data zRelational schema = structure + constraints z(Logical) key = unique tuple identifier zPhysical key (index) = attribute supported by appropriate data structure

3 Implementing relational DBs zDefine the database structure yData Definition Language (DDL) yGraphical definition tools zAllocate media space zPopulate tables

4 Data Definition Language CREATE TABLE MOVIE ( MovieNumberCHARACTER (5)NOT NULL, TitleCHARACTER VARYING (30)NOT NULL, TypeCHARACTER VARYING (10)NOT NULL, YearMadeDATENOT NULL, CriticRatingSMALLINTNOT NULL, MPAARatingCHARACTER VARYING (5)NOT NULL, DirNumberCHARACTER VARYING (5)NOT NULL, PRIMARY KEY( MovieNumber ), FOREIGN KEY( DirNumber ) REFERENCES DIRECTOR )

5 Populate database zFill the database with data via: yimporting ydata entry zAfter population, data must be verified for accuracy

6 DML interfaces zForms/reports zQuery/update language ySQL yStored procedures

7 DML application interfaces zSubroutine calls to DBMS subroutine library zData access commands embedded in program

8 Relational data manipulation zRelational algebra ySet operations zRelational calculus yNon-procedural, theoretical importance zTransform-oriented languages ySQL zQuery-by-example, query-by-form yWe have seen them in Access

9 Relational algebra operators zSelect zProject zJoin zUnion zIntersection zDifference zProduct zDivision

10 Select zExtracts specified rows  SELECT Sells WHERE bar = “Joe’s”

11 Project zExtracts specified attributes zDuplicate tuples are eliminated yPROJECT Sells OVER (beer, price) ySells [beer, price]

12 Union zExtracts rows that belong to either table zAll rows from both A and B without duplicates yUNION A with B yA + B zTables must be union-compatible (same schema): ysame number of attributes yattributes have same domain A B

13 Example:  Find the bars that are either on Maple Street or sell Bud for less than $3 ySells(bar, beer, price) yBars(name, addr)

14 Example revisited  Find the bars that are either on Maple Street or sell Bud for less than $3, again  Invent new names for intermediary relations  Renaming of attributes is implicit in schema of new relation ySells(bar, beer, price) yBars(name, addr)

15 Intersection zExtracts rows that belong to both tables  INTERSECT A WITH B  A  B zTables must be union-compatible A B

16 Difference zExtracts all the rows that belong to B but not to A ySUBTRACT A FROM B yB - A zTables must be union-compatible A B

17 Join zUsed to combine two relations on the basis of a common attribute containing equal (or,...) values yJOIN Sells Bars WHERE Sells.Bar = Bars.Name

18 2 types of join zEquijoin: contains both copies of common attribute zNatural join: yAll attributes with same name are equated yContains only one copy of common attribute yJOIN Sells(bar,beer,price) Bars(bar,addr)

19 Product zCartesian product of two relations zPairs up every row in A with every row in B yPRODUCT A WITH B  A x B zIf A has n rows and B has m rows, then A x B has n x m rows zNote: join is a combination of product, selection, projection (in that order!)

20 Division zExtracts rows from first table which are matched to all of the rows in the second table CUSTOMER CustNoStockNo1 122 31 32 43 52 STOCK StockNo 1 2 DIVIDE CUSTOMER BY STOCK CustNo 1 3

21 Summary of query formats zSELECT table WHERE condition(s) GIVING newtable zPROJECT table OVER (field-list) GIVING newtable zJOIN table1 table2 WHERE condition(s) GIVING newtable zUNION table1 WITH table2 GIVING newtable zINTERSECT table1 WITH table2 GIVING newtable zSUBTRACT table1 FROM table2 GIVING newtable zPRODUCT table1 WITH table2 GIVING newtable zDIVIDE table1 BY table2 GIVING newtable


Download ppt "Foundations of Relational Implementation zImplementing Relational Databases zRelational Data Manipulation zRelational Algebra."

Similar presentations


Ads by Google