Relational Data Model
Relational Data Model
Relational Data Model
Each column of a table is associate with a Column Names Column Data Type
data type. StdID CHAR(8)
Data Type: defines a set of values and StdFirstname VARCHAR(50)
permissible operations on the values. StdLastName VARCHAR(50)
Constraints that are directly applied in the schemas of the data model, by
specifying them in the DDL (Data Definition Language).
Constraints on Relational Database
NULL value: a special value that represents the absence of an actual value. A null
value can mean that the actual value is unknown or does not apply to the given
row
Primary key: a special designed candidate key. The primary key for a table cannot
contain null values.
• can identify the row in the relation (table) uniquely
Entity integrity rules: No two rows of a table can contain the same value for the
primary key and no row can contain a NULL value for any columns of a primary key.
Entity Constraints are also referred to as Key constraints
Integrity Rules
Define fields (which is also known as column headings). Each field must have a
unique name, and data type (may have other constraints in addition)
• Adding Field Names in Table Design View
• Assigning Data Types in Table Design View
• Entering Field Descriptions in Design View
• Setting constraints on Tables
• Saving a Table in Design View
Short Text Contains up to 255 characters of text, or a combination of text, numbers, and other info.
A longer type of text field. It can store up to about 1 GB of text, but controls used to display its
Long Text
values can only show the first 64,000 characters.
Can contain only numeric data on which to perform calculations, NOT phone numbers or zip
Number codes. As you do not perform calculations with these numbers, they are text fields. Can be
either 1, 2, 4, 8, or 16 bytes in size, depending on the related “Field Size” setting.
An 8-byte numeric value which is compatible with the SQL_BIGINT data type in ODBC and
Large Number
which is used for efficiently calculating large numbers that aren’t currency.
Date/Time Contains an 8-byte date or time code. Useful for Date/Time calculations.
Date/Time A 42-byte date or time code similar to the Date/Time data type, but with a larger date range,
Extended higher fractional precision, and compatibility with the “datetime2” data type in SQL Server.
An 8-byte number data type in function, but formatted as currency, with 4 decimal places of
Currency precision. Uses fixed point calculation, which is faster than the Number data type’s floating
point calculation.
Create Tables in Microsoft Access
Assigns a unique 4-byte numeric ID to all records entered in the table. Useful as a primary key
AutoNumber
field. If used for Replication ID, then it instead contains 16 bytes.
Stores Boolean (logical) data, like “Yes/No,” “True/False,” “On/Off,” “-1/0.” Used when only two
Yes/No
possible values in a field can exist.
Connects to objects in Windows-based applications. You can use OLE Object data types for
OLE Object
ActiveX objects, pictures, calendars, and other types of files.
Allows you to attach any type of supported file, such as images, or spreadsheets, for example.
Attachment Provides greater attachment flexibility than the OLE Object field and also uses storage space
more efficiently than OLE fields.
Allows you to create a calculated field, which contains a value that is derived by performing a
Calculated
function on other table fields using an expression that you create.
Not an actual data type. Selecting this instead helps you set up a lookup field, which contains
Lookup Wizard… values from another table, query, or values you enter by hand, which then validate this field’s
values. Useful for combo boxes and list boxes in forms.
Create Tables in Microsoft Access
Constraints enable you to further control how data is entered into a table and are
used to restrict values that can be inserted into a field and to establish referential
integrity.
Constraint Description
NULL/NOT NULL Used to indicate if a field can be left blank when records are entered into a table.
FOREIGN KEY Used to link records of a table to the records of another table.
Note:
• To create a one-to-one relationship Both of the common fields (typically the primary
key and foreign key fields) must have a unique index. This means that the Indexed
property for these fields should be set to Yes (No Duplicates). If both fields have a
unique index, Access creates a one-to-one relationship.
• To create a one-to-many relationship The field on the one side (typically the primary
key) of the relationship must have a unique index. This means that the Indexed
property for this field should be set to Yes (No Duplicates). The field on the many side
should not have a unique index. It can have an index, but it must allow duplicates. This
means that the Indexed property for this field should be set to either No or Yes
(Duplicates OK). When one field has a unique index, and the other does not, Access
creates a one-to-many relationship.
Create Tables in Microsoft Access
NOTE:
Attributes
Domains
Tuples
Relation
• Relation Schema: The name of a relation and a set of attributes for a relation is called
the schema for that relation
A database schema (relational database schema) consist of set of schemas
Relational Algebra
Intersection Operation
R S = { t | t ∈ R and t ∈ S}
Notation: R S
Where R and S are either database relations or relation result set (temporary relation).
Fundamental Operations of Relational Algebra
Selection Operator(σ)
• It selects tuples that satisfy the given predicate from a relation.
Notation: σC(R)
• Where σ stands for selection predicate and R stands for relation. C is prepositional
logic formula which may use connectors like and (), or (), not ( ). These terms
may use relational operators like =, ≠, ≥, < , >, ≤.
• C is called a conditional expression.
Selection Operator
σCrsCredit 3(Course_MI)
CrsNo CrsName CrsCredit
MI3090 Co so du lieu 3
Selection Operator
The relation Students:
StdID StdFirstname StdLastName StdBirthday StdCity StdMajor StdClass StdGPA
OfferNo
∏OfferNo (Enrollment) 11111
11113
∏StdID (Enrollment)
StdID
20191000
20191001
Selection and Projection Operators
The relation schema for the resulting relation is the union of the schemas for R and S. If R
and S have some attributes in common, we need to invent new names for at least one of
each pair of identical attributes. To disambiguate an attribute A that is in the schemas of
both R and S, we use R.A for the attribute from R and S.A for the attribute from S.
A B B C D A R.B S.B C D
1 2 2 3 5 1 2 2 3 5
3 4 4 5 7 1 2 4 5 7
6 7 9 1 2 6 7 9
3 4 2 3 5
Relation R Relation S 3 4 4 5 7
Result R X S 3 4 6 7 9
Natural Join Operator
Natural Join
• Notation: R * S (or R ⋈ S)
• Let attributes A1, A2, … An be common attributes to the schemas of R and S.
• A tuple t from R and a tuple p from S are successfully paired if and only if t and
p agree on each of the attributes A1, A2, … An
• If the tuples t and p are successfully paired in the join R ⋈ S, then the result of
the pairing is a tuple, called the joined tuple, with one component for each of
the attributes in the union of the schemas of R and S. The joined tuple agrees
with tuple t in each attribute in the schema of R, and it agrees with tuple p in
each attribute in the schema of S.
A B B C D A B C D
1 2 ⋈ 2 3 5
= 1 2 3 5
3 4 4 5 7 3 4 5 7
6 7 9
Natural Join Operator
Offering ⋈ Course
OfferNo CrsNo OffTerm OffLocation OffTimeS OffTimeE OffDays CrsName CrsCredit
11111 MI3090 20211 D9-202 4 6 2 Co so du lieu 3
11112 MI3090 20212 D5-301 10 12 5 Co so du lieu 3
11113 MI2000 20211 D3-202 3 6 4 Nhap mon 2
Relation Enrollment: ⋈
OfferNo StdID EnrGrade
11111 20191000 6
11111 20191001 7
11113 20191001 5
? σOffTerm = ‘20211’(Offering ⋈ Course)
? ∏OfferNo, CrsNo, CrsName, OffTerm (σOffTerm = ‘20211’(Offering ⋈ Course))
? ∏ OfferNo, CrsNo, CrsName , OffTerm (σOffTerm = ‘20211’(Offering ⋈ Course)) ⋈ Enrollment
Natural Join Operator
Relation Course CrsNo CrsName CrsCredit
MI2000 Nhap mon 2
MI3090 Co so du lieu 3
EM2000 Nhap mon 2
Relation Offering
OfferNo CrsNo OffTerm OffLocation OffTimeS OffTimeE OffDays
11111 MI3090 20211 D9-202 4 6 2
11112 MI3090 20212 D5-301 10 12 5
11113 MI2000 20211 D3-202 3 6 4
? ∏OfferNo, CrsNo, CrsName, OffTerm (σOffTerm = ‘20211’(Offering ⋈ Course))
? ∏OfferNo,CrsNo,OffTerm (σOffTerm = ‘20211’(Offering)) ⋈ ∏ CrsNo, CrsName (Course)
? ∏OfferNo,CrsNo,OffTerm, CrsName (σOffTerm = ‘20211’(Offering)) ⋈ ∏ CrsNo, CrsName (Course)
NOTE: There is often more than one relational algebra expression that represents the
same computation.
Natural Join Operator
Relation Course: CrsNo CrsName CrsCredit
MI2000 Nhap mon 2
MI3090 Co so du lieu 3
EM2000 Nhap mon 2
Relation Offering
OfferNo CrsNo OffTerm OffLocation OffTimeS OffTimeE OffDays
11111 MI3090 20211 D9-202 4 6 2
11112 MI3090 20212 D5-301 10 12 5
11113 MI2000 20211 D3-202 3 6 4
Theta-Joins
• Notation: R ⋈C S
C is a condition
Called: Conditional Join(⋈c)
A B
1 2 • R ⋈A S A R.B S.B C D
> B
2 3 3 4 2 3 5
3 4
Equijoin
B C D
is equality operator (=)
2 3 5 R ⋈A = B S A R.B S.B C D
4 5 7 2 3 2 3 5
6 7 9
R ⋈B = B S A R.B S.B C D
1 2 2 3 5
3 4 4 5 7
Semijoin Operator
Semijoin (⋉)
Notation: R ⋉ S
• The result is the set of all tuples in R for which there is a tuple in S that is equal on
their common attribute names. The difference from a natural join is that other
columns of S do not appear.
Division Operator