Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relations Prof. Yin-Fu Huang CSIE, NYUST Chapter 6.

Similar presentations


Presentation on theme: "Relations Prof. Yin-Fu Huang CSIE, NYUST Chapter 6."— Presentation transcript:

1 Relations Prof. Yin-Fu Huang CSIE, NYUST Chapter 6

2 Advanced Database SystemYin-Fu Huang 6.1Introduction Relation types, values, and variables 6.2Tuples A set of ordered triples of the form Degree, attribute, heading Major_P# : P#Minor_P# : P#Qty : Qty P2P47

3 Advanced Database SystemYin-Fu Huang Properties of tuples  Every tuple contains exactly one value for each of its attributes.  There is no left-to–right ordering to the components of a tuple.  Every subset of a tuple is a tuple. The tuple type generator e.g. Var Addr Tuple { StreetChar, CityChar, StateChar, ZipChar}; 6.2Tuples (Cont.)

4 Advanced Database SystemYin-Fu Huang Operators on tuples  the tuple selector, assignment, equality comparison  tuple projection, tuple join  Wrap, Unwrap e.g. Naddr1:= Naddr2 Wrap {Street, City, State, Zip} As Addr; Naddr2:= Naddr1 Unwrap Addr; 6.2Tuples (Cont.)

5 Advanced Database SystemYin-Fu Huang 6.3Relation Types A relation value consists of a heading and a body. Relation [ ] { } The relation type generator e.g. Var Part_Structure … Relation {Major_P# P#, Minor_P# P#, Qty Qty} … ;

6 Advanced Database SystemYin-Fu Huang 6.4Relation Values Properties of relations (See Fig. 6.1)  Relations are normalized. ⇒ first normal form  Attributes are unordered, left to right.  Tuples are unordered, top to bottom.  There are no duplicate tuples. Relations vs. Tables

7 Advanced Database SystemYin-Fu Huang 6.4Relation Values (Cont.) Relation-valued attributes (See Fig. 6.2)

8 Advanced Database SystemYin-Fu Huang 6.4Relation Values (Cont.) Relations with no attributes  There are precisely two relations of degree zero-one that contains just one tuple, and one that contains no tuples at all. i.e. Table_Dee: Relation { } { Tuple{ } } Table_Dum: Relation { } { } Operators on relations  Relational comparisons  Other operators:   Order By

9 Advanced Database SystemYin-Fu Huang 6.5Relation Variables Base Relvar definition  Var Base [ ]; e.g. Var SP Base Relation {S# S#, P# P#, Qty Qty} Primary key {S#, P#} Foreign key {S#} References S Foreign key {P#} References P;  Drop Var ;

10 Advanced Database SystemYin-Fu Huang 6.5Relation Variables (Cont.) Updating Relvars ::= ; ::= := ; e.g. S’:=S Where Not (City=’Paris’); Insert ; Delete [Where ]; Update [Where ] {attribute update commalist>};

11 Advanced Database SystemYin-Fu Huang 6.6 6.6SQL Facilities Rows  A left-to-right ordering [Row] ( ) Table Types  A left-to-right ordering  Duplicated rows Values

12 Advanced Database SystemYin-Fu Huang 6.6 6.6SQL Facilities (Cont.) Table values and variables  Create Table ( ); : 1. 2. : [ ]  Drop Table : Restrict or Cascade  Alter Table e.g. Alter Table S Add Column Discount Integer Default -1;

13 Advanced Database SystemYin-Fu Huang 6.6 6.6SQL Facilities (Cont.) Structured Types e.g. Create Type Point As (X Float, Y Float) Not Final Ref Is System Generated; Create Table Points Of Point (Ref Is Point# System Generated …); In the example, base table Points actually has three columns (Point#, X, and Y, in that order).

14 Advanced Database SystemYin-Fu Huang The End.


Download ppt "Relations Prof. Yin-Fu Huang CSIE, NYUST Chapter 6."

Similar presentations


Ads by Google