Download presentation
Presentation is loading. Please wait.
Published byRoy Barrett Modified over 9 years ago
1
CS 3630 Database Design and Implementation
2
2 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1 A2 A3 … An = {(x1, x2, x3, …, xn): xi Ai} R A1 A2 A3 … An
3
3 Mapping and Relation R1 = {(1, 2), (1, 5), (2, 5)} = {(x, y) | x is in A, y is in B, x < y and x <= 2} A relationship between A and B 12341234 2525
4
4 How Many Possible Relations/Mappings between A and B A = {1, 2, 3, 4} B = {2, 5} R A B
5
5 Functions A function is a mapping y = f(x) x in a set Domain y in a set Range Mapping from Domain to Range
6
6 Total or Partial y = f(x) = x 2. 1.2 2 -2 4. 1.44 4 -4 16. Total Domain Real Numbers Range Real Numbers Partial
7
7 Total or Partial y = f(x) = x 2. 1.2 2 -2 4. 1.44 4 16. Total Domain Real Numbers Range Non-negative Real Numbers Total
8
8 Functions A function is a mapping y = f(x) x in a set Domain y in a set Range One-to-one? One-to-Many? Many-to-one?
9
9 Functions y = f(x) For the same value of x, the value of y always the same. y1 = f(3) u = 2 y2 = f(u + 1) Both y1 and y2 must have the same value! It CANNOT be one-to-many!
10
10 Functions But for different values of x, the value of y could be the same. y = f(x) = x 2 f(2) = f(-2) It’s not one-to-one! It could be many-to-one.
11
11 Relation Example Student = {s: s is a student registered at UWP this semester} Course = {c: c is a course offered at UWP this semester}
12
12 Student Taking Course Student Course S9 S2 S4 S5 C1 C2 C3 C5 Partial or Total?
13
13 Example S = {s | s is a student registered at UWP this semester} C = {c | c is a course offered at UWP this semester} S C: All possible registrations Registration = {(s, c): (s, c) S C and s is taking c} Partial for both S and C Many-to-many It can be updated!
14
14 Terminology A = {1, 2, 3, 4} B = {2, 5} R1 = {(1, 2), (1, 5), (2, 5)} R1 A B Tuple: (1, 2), (1, 5) and (2, 5) Cardinality: 3 Domain: A for the 1 st component B for the 2 nd component
15
15 Using Tables for Relations Att1Att2 Att3 15x 510w 42x 35y R = {(1, 5, x), (4, 2, x), (3, 5, y), (5, 10, w)}
16
16 Database Relations (Tables) Relation (Table) Attribute (Field, column) Tuple (Record, row) Domain for each field Degree (number of fields): 3 Cardinality (number of records): 4 Att1Att2 Att3 15x 510w 42x 35y
17
17 Table Instance A subset of the Cartesian Product No duplicates Update Tuples can be modified New tuples can be inserted Old tuples can be deleted Different instance after update Student Course S2C2 S3C2 S2C5
18
18 Relation Schema A named relation defined by a set of attribute and domain pairs. R (Att1:A1, Att2:A2, Att3:A3) R (Att1, Att2, Att3) Domain: Att1: A1 Att2: A2 Att3: A3 The relation schema represents the Cartesian Product A1 A2 A3 Same table schema, different table instances.
19
19 Relational Model What is a Relational Database? A collection of relations (tables) Relational Database: A collection of normalized relations (tables) with distinct relation/table names.
20
20 Database Schema Collection of Relation Schemas Database definition
21
21 Database Instance Relation instances (Tables) Actual records Store Data Update Data Retrieve Data
22
22 Properties of Relations Each relation has a distinct name (within the database) Each attribute has a distinct name (within the relation) Each tuple is distinct Each cell contains exactly one atomic (single) value The order of attributes has no significance The order of tuples has no significance
23
23 Database UWP Student(ID, Name, Phone, Address…) Course(ID, Title, Department, Credits…) Faculty(ID, Name, Department, Phone, Address…) Registration (Student, Course) Other possible fields? Schedule (Faculty, Course) Other possible fields? Other tables
24
Chapter 3 The Relational Model 3.2 Terminology 24
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.