Upload
anne-franklin
View
215
Download
0
Embed Size (px)
DESCRIPTION
Advanced Database SystemYin-Fu Huang 5.1Introduction (Cont.) Informal equivalents (See Fig. 5.2)
Citation preview
TypesTypes
Prof. Yin-Fu HuangProf. Yin-Fu HuangCSIE, NYUST CSIE, NYUST
Chapter 5Chapter 5
Advanced Database System Yin-Fu Huang
Relation, tuple, cardinality, attribute, degree, domain, primary key. (See Fig. 5.1)
5.15.1 IntroductionIntroduction
Advanced Database System Yin-Fu Huang
5.15.1 Introduction (Cont.)Introduction (Cont.) Informal equivalents (See Fig. 5.2)
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’)
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
Advanced Database System Yin-Fu Huang
5.35.3 Relation Values (Cont.)Relation Values (Cont.) Relation-Valued attributes (See Fig. 5.3)
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’);
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
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
Advanced Database System Yin-Fu Huang
The End.