0% found this document useful (0 votes)
27 views23 pages

Relational Data Model-1-23

The document discusses the relational data model and relational databases. It covers key concepts like tables, constraints, integrity rules and relational algebra operators. The goals are to understand relational database terminology, integrity rules for maintaining relational data, and how to combine tables to obtain results for queries. It also provides examples of table definitions and the relationships between tables.

Uploaded by

Le Hieu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views23 pages

Relational Data Model-1-23

The document discusses the relational data model and relational databases. It covers key concepts like tables, constraints, integrity rules and relational algebra operators. The goals are to understand relational database terminology, integrity rules for maintaining relational data, and how to combine tables to obtain results for queries. It also provides examples of table definitions and the relationships between tables.

Uploaded by

Le Hieu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Database Systems

The Relational Data Model


The Relational Data Model

 Learning Objectives: Understand the foundation for using relational databases


• Recognize relational database terminology
• Understand the meaning of the integrity rules for relational databases
• Understand the impact of referenced rows on maintaining relational databases
• Understand the meaning of each relational algebra operator
• List tables that must be combined to obtain desired results for simple retrieval
requests
 Tables
 Constraints on Relational Database
 Operators of Relational Algebra
Tables

 A relational DB consists of a collection tables. Each table has a heading or


definition part and a body or content part.
• The heading part consists of table name and the column names
• The body shows the rows of table.
 A table has rows and columns, where rows represents records and columns
represent the attributes.
 Tuple − A single row of a table, which contains a single record for that relation is
called a tuple.
 Attribute domain − Every attribute has some pre-defined value scope, known as
attribute domain.
Tables

 Example: Students Table


• Table name: Students
• Column names: StdID, StdFirstname, StdLastName, StdBirthday, StdCity, StdMajor,
StdClass, StdGPA

StdID StdFirstname StdLastName StdBirthday StdCity StdMajor StdClass StdGPA

20191000 Nguyen Thi Mai 11/01/2001 Ha Noi EM Ke toan 3.5

20191001 Le Van Nam 22/2/2001 Hai MI Toan Tin 3.2


Phong
Tables

 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)

• Each data type has a name and ussually a StdBirthday DATE


length specification. StdCity VARCHAR(30)
StdMajor CHAR(6)
StdClass VARCHAR(20)
StdGPA DECIMAL(3,2)
Tables

 Alternative Terminology for Relational DB


Table-Oriented Set-Oriented Record-Oriented
Table Relation Record type, File
Row Tuple Record
Column Attribute Field

 Relation instance − A finite set of tuples in the relational database system


represents relation instance. Relation instances do not have duplicate tuples.
 Relation schema − A relation schema describes the relation name (table name),
attributes, and their names.
Constraints on Relational Database

 Constraints: the rules enforced on the data columns of a table.


• Domain constraints, NOT NULL constraints, ….
• Entity Integrity constraints (Ràng buộc toàn vẹn thực thể)
• Referential integrity constraints (Ràng buộc toàn vẹn tham chiếu)

 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

StdID StdFirstname StdLastName StdBirthday StdCity StdMajor StdClass StdGPA

20191000 Nguyen Thi Mai 11/01/2001 Ha Noi EM Ke toan 3.5

20191001 Le Van Nam Hai Phong MI Toan Tin 3.2

Tran Thi Cuc


Constraints on Relational Database

 Domain constraints (Ràng buộc miền):


• Every domain must contain atomic values(smallest indivisible units) it means
composite and multi-valued attributes are not allowed.
• We perform datatype check here, which means when we assign a data type to a
column we limit the values that it can contain. Domain constraints can be violated if an
attribute value is not appearing in the corresponding domain or it is not of the
appropriate data type.
• Domain constraints specify that within each tuple, and the value of each attribute
must be unique. This is specified as data types which include standard data types
integers, real numbers, characters, Booleans, variable length strings, etc.
Integrity Rules

 A relational database consists of a collection of interrelated tables. To ensure that


a database provides meaningful information, integrity rules are necessary.
• Entity integrity
• Referential integrity
Integrity Rules

 Superkey: a column or combination of column containing unique for each row.


• Unique means that no two rows of a table have the same value.
• The combination of every column in a table is always a superkey because rows in a
table must be unique (*SQL does not require*)
 Key (candidate key, unique key): a minimal superkey. A superkey is minimal if
removing any columns makes it no longer unique.

StdID StdFirstname StdLastName StdBirthday StdCity StdMajor StdClass StdGPA

20191000 Nguyen Thi Mai 11/01/2001 Ha Noi EM Ke toan 3.5

20191001 Le Van Nam 22/2/2001 Hai MI Toan Tin 3.2


Phong
Integrity Rules

 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

 Course Table: CrsNo CrsName CrsCredit


MI2000 Nhap mon 2
MI3090 Co so du lieu 3
EM2000 Nhap mon 2
 Offering Table

OfferNo CrsNo OffTerm OffLocation OffTimeS OffTimeE OffDays


11111 MI3090 20211 D9-202 4 6 2
11112 MI3090 20212 D5-301 10 12 5

 Enrollment Table
OfferNo StdID EnrGrade
20191000 EM2000 6
20191001 MI2000 7
20191001 MI3090 5
Integrity Rules
 Connection among Tables: Relationship connection between rows in two tables.
Relationships are shown by column values in one table that match column values
in another table.
 Referential integrity means that the values of columns in one table (the child table)
must match the values of columns in other tables (the parent table)
 Foreign key: a column or combination of columns in which the values must match
those of a candidate key. A foreign key must have the same data type as its
associated candidate key.
• Only two kinds of values can be stored in a foreign key:
 A value matching a candidate key value in some row of the table containing the associated
candidate key
 Or a null value
Questions and Problems

 What is the difference between a primery key and a candidate key?


 What is the difference between a superkey and a candidate key?
 What is the motivation for the entity/referential integrity rule?
 Give relation schema for a simplified Order Entry Database
• Customer
• Order
• Employee
Create Tables in Microsoft Access

 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

 Create relationship between tables in MS Access.


Create Tables in Microsoft Access
DataType Name: Data Type Description:

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.

Hyperlink Contains a hyperlink to an address or file on the Internet, intranet, or LAN.

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.

PRIMARY KEY Used to uniquely identify every record in a table.

FOREIGN KEY Used to link records of a table to the records of another table.

UNIQUE Used to ensure that every value in a column is different.


CHECK Used to set criterion for the data entered into a column.
Create Tables in Microsoft Access

 Setting Referential Integrity


• referential integrity is a system of rules used to ensure that relationships between
records in related tables are valid.
• can enforce referential integrity when you create a relationship, or you can enforce it
later by double-clicking on the relationship lines between the tables that you want to
use. Click on Enforce Referential Integrity in the window that appears.
Create Tables in Microsoft Access

 Set the join type


• 1-M relationship: a connection between two tables in which one row of a table can be
referenced by many rows of a second table. 1-M relationships are the most common
kind of relationship.
• M-N relationship: a connection between two tables in which rows of each table can be
related to many rows of the other table. M-N relationships cannot be directly
represented in the relational model. Two 1-M relationships and a linking or associative
table represent an M-N relationship.
• 1-1 relationship: a connection between two tables in which rows of each table can be
related to one row of the other table.
Create Tables in Microsoft Access

 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

 Turn referential integrity on


• Enforce Referential Integrity.
• Cascade Update Related Fields: When you change data in the main field of one table,
Access will automatically update the matching data in the related table.
• Cascade Delete Related Records: When you delete a record in the main table, Access
will automatically delete any matching records in the related table.

You might also like