100 likes | 107 Views
This section introduces the concepts of relation, tuple, and cardinality in a database system. It also discusses attributes, degree, domain, and primary key.
E N D
5.1 Introduction • Relation, tuple, cardinality, attribute, degree, domain, primary key. (See Fig. 5.1) Advanced Database System
5.1 Introduction (Cont.) • Informal equivalents (See Fig. 5.2) Advanced Database System
5.2 Domains • A domain is nothing more nor less than a data type. e.g. P.Weight+SP.Qty ? P.Weight*SP.Qty P.Weight=SP.Qty ? P.City=S.City • Values Are Typed • Type Definition Type <type name> <possible representation> … ; e.g. Type S# Possrep (Char); Drop Type <type name>; • Possible Representations • A select operator and a set of The_operators • Operator Definition • Type Conversion e.g. S# (‘S1’) Advanced Database System
5.3 Relation Values • Given a collection of n types or domains Ti (i=1, 2, …, n), not necessarily all distinct, r is a relation on those types if it consists of two parts, a heading and a body. • The heading is a set of n attributes of the form Ai:Ti • The body is a set of m tuples t, where t in turn is a set of components of the form Ai:vi • Example {S#:S#, {S#:S#(‘S1’), Sname:Name, Sname:Name(‘Smith’), Status:Status, Status:20, City:City} City:‘London’} • Properties of Relations a. There are no duplicate tuples. b. Tuples are unordered, top to bottom. c. Attributes are unordered, left to right. d. Each tuple contains exactly one value for each attribute. ⇒ first normal form Advanced Database System
5.3 Relation Values (Cont.) • Relation-Valued attributes (See Fig. 5.3) Advanced Database System
5.4 Relation Variables • Base Relvar definition Var <relvar name> Base <relation type> <candidate key definition list> [<foreign key definition list>]; 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 <relvar name>; • Updating Relvars <relvar name>:=<relational expression>; e.g. S:=S Minus (S Where City=’Paris’); Advanced Database System
5.5 SQL Facilities Create Domain Create Table Insert Alter Domain Alter Table Update Drop Domain Drop Table Delete • Domain • Create Domain <domain name> <built type name> [<default spec>] [<constraints>]; • Drop Domain <domain name> <option>; • option: Restrict or Cascade Advanced Database System
5.5 SQL Facilities (Cont.) • Base Table • SQL tables are allowed to include duplicate rows. • SQL tables are considered to have a left-to-right column ordering. • Create Table <base table name> (<base table element commalist>); • <base table element>: 1. <column definition> 2. <constraint> • Column definition <column name> <type or domain name> [<default spec>] • Alter Table e.g. Alter Table S Add Column Discount Integer Default -1; • Drop Table <base table name> <option> • option: Restrict or Cascade Advanced Database System
The End. Advanced Database System