10
Types Types Prof. Yin-Fu Huang Prof. Yin-Fu Huang CSIE, NYUST CSIE, NYUST Chapter 5 Chapter 5

Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Embed Size (px)

DESCRIPTION

Advanced Database SystemYin-Fu Huang 5.1Introduction (Cont.) Informal equivalents (See Fig. 5.2)

Citation preview

Page 1: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

TypesTypes

Prof. Yin-Fu HuangProf. Yin-Fu HuangCSIE, NYUST CSIE, NYUST

Chapter 5Chapter 5

Page 2: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

Relation, tuple, cardinality, attribute, degree, domain, primary key. (See Fig. 5.1)

5.15.1 IntroductionIntroduction

Page 3: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

5.15.1 Introduction (Cont.)Introduction (Cont.) Informal equivalents (See Fig. 5.2)

Page 4: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

5.25.2 DomainsDomains

A domain is nothing more nor less than a data type.e.g. P.Weight+SP.Qty ?

P.Weight*SP.QtyP.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’)

Page 5: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

5.35.3 Relation ValuesRelation Values Given a collection of n types or domains Ti (i=1, 2, …, n), not necessarily all di

stinct, 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 Relationsa. 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

Page 6: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

5.35.3 Relation Values (Cont.)Relation Values (Cont.) Relation-Valued attributes (See Fig. 5.3)

Page 7: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

5.45.4 Relation VariablesRelation 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 SForeign key {P#} References P;

Drop Var <relvar name>; Updating Relvars

<relvar name>:=<relational expression>;e.g. S:=S Minus (S Where City=’Paris’);

Page 8: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

5.55.5 SQL FacilitiesCreate Domain Create Table InsertAlter Domain Alter Table UpdateDrop Domain Drop Table Delete

DomainCreate Domain <domain name> <built type name>

[<default spec>][<constraints>];

Drop Domain <domain name> <option>;• option: Restrict or Cascade

Page 9: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

5.55.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

Page 10: Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary

Advanced Database System Yin-Fu Huang

The End.