Relations Prof. Yin-Fu Huang CSIE, NYUST Chapter 6
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
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.)
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.)
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} … ;
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
Advanced Database SystemYin-Fu Huang 6.4Relation Values (Cont.) Relation-valued attributes (See Fig. 6.2)
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
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 ;
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>};
Advanced Database SystemYin-Fu Huang SQL Facilities Rows A left-to-right ordering [Row] ( ) Table Types A left-to-right ordering Duplicated rows Values
Advanced Database SystemYin-Fu Huang SQL Facilities (Cont.) Table values and variables Create Table ( ); : : [ ] Drop Table : Restrict or Cascade Alter Table e.g. Alter Table S Add Column Discount Integer Default -1;
Advanced Database SystemYin-Fu Huang SQL 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).
Advanced Database SystemYin-Fu Huang The End.