0% found this document useful (0 votes)
188 views33 pages

2.1 - Chapter 2 - Relational Database Modeling - P1

The document discusses the relational data model. It defines key concepts like relations, attributes, tuples, domains, relation instances, and database schemas. Relations are represented as tables with rows (tuples) and columns (attributes). The schema specifies the relation name and attributes. A tuple is a row, and domains define the type of each attribute. The order of tuples is unimportant as relations are sets. Keys uniquely identify tuples. SQL can be used to define relation schemas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
188 views33 pages

2.1 - Chapter 2 - Relational Database Modeling - P1

The document discusses the relational data model. It defines key concepts like relations, attributes, tuples, domains, relation instances, and database schemas. Relations are represented as tables with rows (tuples) and columns (attributes). The schema specifies the relation name and attributes. A tuple is a row, and domains define the type of each attribute. The order of tuples is unimportant as relations are sets. Keys uniquely identify tuples. SQL can be used to define relation schemas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

ĐẠI HỌC FPT CẦN THƠ

Chapter 2
Relational Data Model - Part 1
Objectives

1 Understand what is a Data Model

2 Understand what belong to a Data Model

3 Understand what are Relations, Attributes, Tuples, Domains

4 Understand what are Relation instances, Schema, DB schema

55 Understand how to use SQL to define relation schemas


Contents

1 An Overview of Data Models

2 Basics of the Relational Model

3 Defining a Relation Schema in SQL


2.1. An Overview of Data Models
2.1.1. What is a Data Model?

A Data Model is a notation for describing data,


including 3 parts:
Structure of the data: Arrays or objects, for
example
Operations on data: queries, modifications
Constraints: Limitations on the data
2.1.2.Important Data Models

Today, two important data models are:


The relational model, including object-relational
extensions
The semi-structured data model, including XML
and related standards
2.1.3. Overview of
Relational Model
2.1.4. Overview of
Semi-structured Data

Another data model, based on trees rather than


tables or arrays.
The point-of-view today is XML: a way to
represent data by hierarchically nested tagged
elements.
XML file
2.2. Basics of Relational Model
2.2.1. Attributes
The relational model represents data as a
2-dimensional table (called a relation)
For example: CUSTOMERS relation
2.2.1. Attributes

Each row represents a CUSTOMER


Each column represent a property of
CUSTOMER and also called a “attribute”

How many Attributes in the table? What are they?


2.2.1. Attributes

4 Attributes
2.2.2. Schemas

The name of a relation and the set of attributes for


that relation is called the schema for that relation.

What is the schema in the table?


2.2.2. Schemas

The schema for the relation:

CUSTOMERS (Customer ID, Tax ID, Name, Address)


2.2.3. Tuples
A row of a relation is called a tuple (or record)
When we want to write a tuple in isolation, not as
part of a relation, we normally use commas to
separate components
2.2.3. Tuples

A row of a relation is called a tuple (or record)


When we want to write a tuple in isolation, not
as part of a relation, we normally use commas to
separate components
Exp: (1234567890,555-5512222, Munmun, 323
Broadway)
2.2.3. Tuples
A row of a relation is called a tuple (or record)
When we want to write a tuple in isolation, not as part
of a relation, we normally use commas to separate
components
How many Tuples in the table?
What are they?
2.2.4. Domains

The relational model requires that each component of


each tuple must be atomic, that is, it must be of
some elementary type such as INTEGER or STRING
It is not permitted for a value to be a record
structure, set, list, array or any type that can have its
values broken into smaller components
A domain is a particular elementary type of a
attribute
2.2.5. Equivalent representation
of a relation

Relations are sets of tuples, not lists of tuples


So, the order in which the tuples of a relation are
presented is …
A. important
B. not important
2.2.5. Equivalent representation
of a relation

Relations are sets of tuples, not lists of tuples


So, the order in which the tuples of a relation are
presented is not important
2.2.6. Relation instances

A relation about CUSTOMERS is not static but


changing over time:
We want to insert tuples for new CUSTOMER as
these appear
We want to edit existing tuples if we get
corrected information about a CUSTOMER
We want to delete a tuple from the database
A set of tuples for a given relation is called an
instance of that relation
2.2.7. Keys of relations
A set of attributes forms a key for a relation if we
don’t allow 2 tuples in a relation instance to have the
same values in all the attributes of the key

What is the key of relation


CUSTOMERS (Customer ID, Tax ID, Name, Address)?
2.2.7. Keys of relations
The key of relation
CUSTOMER (Customer ID, Tax ID, Name, Address)
is CustomerID or TaxID
2.3. Defining a Relation Schema in SQL
2.3. Defining
a Relation Schema in SQL

2.3.1. Relations in SQL


2.3.2. Data Types
2.3.3. Simple Table Declarations
2.3.4. Modifying Relation Schemas
2.3.5. Default Values
2.3.6. Declaring Keys
Summary 1: Relational Model
? = relation.
? = attributes.
? = ?= tuple
? = name (attributes) + other structure info.,
e.g., keys, other constraints. Example: Beers(name,
manf)
Order of attributes is important or not?
? = set of rows for a relation schema.
? = collection of relation schemas.
Summary 1: Relational Model
Table = relation.
Column headers = attributes.
Row = record = tuple
Relation schema = name (attributes) + other structure info.,
e.g., keys, other constraints. Example: Beers(name,
manf)
Order of attributes is arbitrary, but in practice we need to
assume the order given in the relation schema.
Relation instance is current set of rows for a relation
schema.
Database schema = collection of relation schemas.
Summary 2: Why Relations?

?
Summary 2: Why Relations?

Very simple model.


Often a good match for the way we think about
our data.
Abstract model that underlies SQL, the most
important language in DBMS’s today.
But SQL uses “bags” while the abstract relational model
is set-oriented.
Exercises

Write SQL queries to create the following


Schemas in SQL Server:
Address(House#, StreetName, City, Province, Country)
Salaries(ID, IDPerson, PersonName, SalaryValue,
Month, Year)
Contacts(ID, ContactName, Address, Tel, eMail)
Write SQL queries to drop the above tables
Tools

MS SQL Server
SQL Server Management Studio
https://www.c-sharpcorner.com/article/step-
by-step-installation-of-microsoft-sql-server-o
n-windows-system/
ĐẠI HỌC FPT CẦN THƠ

You might also like