Download Characteristic of data record in relation

Document related concepts

Microsoft SQL Server wikipedia , lookup

Oracle Database wikipedia , lookup

Open Database Connectivity wikipedia , lookup

IMDb wikipedia , lookup

Ingres (database) wikipedia , lookup

Concurrency control wikipedia , lookup

Relational algebra wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Database wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Clusterpoint wikipedia , lookup

ContactPoint wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

Transcript
954245
Chapter 2
Relational Database
Modern Management and Information Technology
Collage of Arts, Media and Technology
Chiang Mai University
Outline
1. The range of database applications
2. Relational database (definition and
characteristic)
3. Key
4. Data Integrity Rules
5. Relationship
What can databases help us do?
Database System Concept
1. The Range of Database Applications
• It is important to understand that the applications and the
database do not need to reside on the same computer.
• We divide the range of database applications into three
categories based on the location of the client (application)
and the database software itself
1. Personal
2. Two-tier
3. Multitier databases
Personal Database
• Are designed to support one user and have long resided on
PCs, laptops, smart phones and PDAs.
• Widely used because they improve personal productivity
• The data cannot easily be shared with other users and has
other limitations
Personal Database
Purpose
• To provide the user with the ability to manage (store, update,
delete, and retrieve) small amounts of data in and efficient
manner.
For example
store customer information and the details of contacts
consider a company that has a number of salespersons who call
on actual or prospective customers
A database of customers and pricing application can enable the
salesperson to determine the best combination of quantity and
type of items for the customer to order.
Two-tier Database with LAN
Characteristics of twotier databases
• Workgroup
• Linked by network
• Sharing data
• Different user views
(Authentication)
Two-tier Client/Server Database
• The most common method of sharing data for user by
creating a two-tier client/server application
• Each member of the workgroup has computer and linked by
network (LAN)
• Database and database management system are stored on
a central device called the database server (connected to
network)
• Each member of workgroup has access to the shared data
• Different group members may have different user views of
the shared database
Multitier Client/Server Database (n-tier)
• The most significant implication for database development
form the use of multitier client/server architectures is the
ease of separating the development of the database and the
modules that maintain the data from the information system
modules that focus on business logic and / or presentation
logic
• This architecture allows to improve performance and
maintain ability of the application and database
Three-tier Architectures
•Popular choice for internet application
•Includes another server layer in addition to the
client and database server layers
•Increase scalability, flexibility, performance, and
reusability
Three-tier
Architectures
Three-tier Architecture
• Workgroup has several
multitier applications
(between 25 and 100 persons)
• User interface is accessible on
the individual user’s
computers
• User interface: web browser
based (written by Visual
Basic.NET, Visual C#, or Java
• Application layer: contains the
business logic required to
accomplish the business
n-tier
• Client
• Server
Application
servers
Database
servers
Management
server
Summary of Database Applications
Type of
Typical Number of
Database/Application Users
Personal
1
Two-tier
5-100
Three-tier
100-1,000
Enterprise resource
>100
planning (ERP)
Data warehousing
>100
Typical Size of
Database
Megabytes
Megabytes-gigabytes
Gigabytes
Gigabytes-terabytes
Terabytes-petabytes
Technical term
technical term
• Relation
• Tuple
• Attribute
• Cardinality
• Primary Key
word
Table
Row , Record
Column, Field
Number of Rows
Unique Identifier
2. Relational Database
• The notion "relational" is motivated by the mathematical
concept of a relation. Relations in mathematics are sets of
tuples.
• Relational databases are collections of one or more
relations.
• In practice, relations can be visualized as tables, the rows of
which are individual records of data with the same
(homogeneous) field structure.
The idea to organize data in tables is quite old and pretty
obvious.
• The idea to investigate this representation of data by means
Relational Database (RDB)
• A relational database (RDB) is a collective set of multiple
data sets organized by tables, records and columns. RDBs
establish a well-defined relationship between database
tables. Tables communicate and share information, which
facilitates data searchability, organization and reporting.
• RDBs use Structured Query Language (SQL), which is a
standard user application that provides an easy
programming interface for database interaction.
Relational Database
Definition
• There are a set of tables.
• The name of table is the name of relation.
• The columns in relation are called attributes.
• Domain is defined to data in the attribute that has
same data type.
• The rows are called tuples.
Relational Database
Attributes
• Degree is the
number of
attributes.
• Cardinality is the
number of rows.
EmployeeNumber
100
700
300
40
• Degree =3
• Cardinality4 =
FirstName
Mary
Jerry
Alea
Murugan
LastName
Abermany
Caldera
Copley
Jacksoni
Characteristic of data record in relation
1. No repeating data in each row
Characteristic of data record in relation
2. The order of data in each row is insignificant.
Characteristic of data record in relation
3. The order of data in each attribute is meaningless.
Characteristic of data record in relation
4. For each attributes, it can record only 1 value.
Characteristic of data record in relation
5. The value in each attribute record data in the same
domain.
RDBs have many other advantages
• Easy extendibility, as new data may be added without
modifying existing records. This is also known as scalability.
• New technology performance, power and flexibility with
multiple data requirement capabilities.
• Data security, which is critical when data sharing is based on
privacy. For example, management may share certain data
privileges and access and block employees from other data,
such as confidential salary or benefit information.
3. Key
•Primary Key (PK)
•Foreign Key (FK)
•Candidate Key
•Composite Key
Primary Key (PK)
• An attribute or a
combination of
attributes that
uniquely identifies
each row in a
•relation
Uniqueness and
minimal
Foreign key (FK)
• An attribute in a relation that serves as the primary key of
another relation in the same database
• database must not contain any
unmatched foreign key values.
Foreign keys
provide the
between
Candidate key (CK)
• An attribute, or combination of attributes, that uniquely
identifies a row in a relation
candidate key
Composite key
• A primary key that consists of more than one attribute
• More than one attribute is needed to make the entity unique
Registration database
Please list all of PK, FK, CK?
Student_ Course_i ter
id
d
m
Academic_ye
ar
sectio grad Lecturer_i
n
e
d
Student_i name surnam addres Telephone_n
d
e
s
o
Lecture_ LName
id
LSurnam Telephon Major_id
e
e
Course_ Course_na
id
me
Major_i
d
Major_nam
e
Descriptio Unit Typ
n
e
Null Values
• NULL is not the number zero.
• NULL is not the empty string value.
• NULL is the value used to represent an unknown piece of
data.
• Comparisons between two null values, or between a NULL
and any other value, return unknown because the value of
each NULL is unknown.
4. Data Integrity Rules/Integrity
Constraints
•The relational data model includes several types
of constraints, or rules limiting accept- able
values and actions, whose purpose is to facilitate
maintaining the accuracy and integrity of data in
the database.
•The major types of integrity constraints are
domain constraints, entity integrity, and
referential integrity
4. Data Integrity Rules
Data integrity rule is a procedure to control the
accuracy and consistency of data stored in a
database.
There are 3 rules:

Entity Integrity

Domain Integrity
Entity Integrity
•Every table must have a primary key and that the
column or columns chosen to be the primary key should
be unique and not null.
Code
441210073
441210093
Name
แก้ ว ใจเพชร
มานี ใจใส่
มานะ ใจดี
ปิ ติ ใจซื่อ
Entity Integrity
• Is designed to ensure that every relation has a primary
key and that the data values for that primary key are
all valid
• Guarantees that every primary key attribute is non-null
Entity integrity rule
• No primary key attribute (or component of a primary
key attribute) may be null
Domain Integrity
•Domain integrity means the definition of a valid set
of values for an attribute. You define
Pcode Pname Ptype QTY Price
- data type,
- length or size
001 ปากกา
01
10
5
- is null value allowed 002 ดินสอ 01
20
2
- is the value unique or not
003
โต๊ ะ
03
5.5 1,600
for an attribute.
004 โคมไฟ
02
4
500
Domain Integrity
• All of the values that appear in a column of a relation
must be from the same domain
• Domain is the set of values that may be assigned to an
attribute
• Domain definition usually consists of the following
components: domain name, meaning, data type, size
(or length), and allowable values or allowable range (if
applicable)
Domain Definitions for INVOICE
Attributes
Attribute
Domain
Name
Cust_ID
Customer ID
Cust_Name Customer
Names
Order_ID
Order ID
OrderDate Order Dates
Description
Domain
Set of all possible customer ID
Set of all possible customer
names
Set of all possible order ID
Set of all possible order dates
Character: size 5
Character: size 25
Product_ID Product ID
Set of all possible product ID
Character: size 5
Date: format
mm/dd/yy
Character: size 5
Referential Integrity
• Any value of
foreign key in
the relation
must be refer to
the primary key
value in
another
relation.
Otherwise it
Product
Pcode
001
002
003
004
Pname
Ptype
QTY
Price
ปากกา
01
10
ดินสอ
20
โต๊ ะคอมฯ
03
5
โคมไฟ
02
4
Product Type
Ptype
Pname
5
2
1,600
500
Location
01
เครื่ องเขียน
A2
02
ไฟฟ้า
A5
Referential Integrity
• Is a rule that maintains consistency among the rows of
two relations
• If there is a foreign key in one relation, either each
foreign key value must match a primary key value in
another relation or the foreign key value must be null
Referential integrity constraint
• A rule that states that either each foreign key value
must match a primary key value in another relation or
the foreign key value must be null
Modification affect to Referential
Integrity
•Delete the rows in the relation that their primary
key are the foreign key in another relation.
•Modify the primary key value in the relation that
refer to foreign key in another relation.
Modification affect to Referential
Integrity Pcode Pname Ptype
QTY
Product
001
002
003
004
ปากกา
ดินสอ
โต๊ ะคอมฯ
โคมไฟ
01
01
02
02
10
20
5
4
Price
5
2
1,600
500
Break the rule
Product Type
Ptype
Pname
Location
01
เครื่ องเขียน
A2
02
ไฟฟ้า
A5
Change 02 to 04
3 cases to keep Referential Integrity
1. Cascade
changing the primary key of a row in the primary table, the foreign
key values are updated in the matching rows in the related table.
2. Restricted
changing the primary key of a row in the primary table can be done
when there not refer to another relation as foreign key. Otherwise,
modification can not be done.
3. Nullifies
changing the primary key of a row in the primary table, the foreign
Classification of relation
1. Base Relation
Base Relation is a storage relation
2. View
Relation that are authorized some views to
each user
5. Relationship
•Each table is known as a relation, which contains
one or more data category columns.
•Each table record (or row) contains a unique data
instance defined for a corresponding column
category. One or more data or record
characteristics relate to one or many records to
form functional dependencies.
Types of relationships in database
• There are four relationships in database
One to One (1-1):
• One table record relates to another record in another table
• One entity is associated with another entity. For Ex: Each
employee is associated with one department
One to Many (1-M):
• One table record relates to many records in another table
• One entity is associated with many other entities. For Ex: A
company is associated with all working employees in one
Types of relationships in database
Many to One (M-1)
• Many entities are associated with only one entity. For Ex:
Many employees are associated with one project.
Many to Many (M-N)
• More than one table record relates to more than one record
in another table
• Many entities are associated with many other entities. For
Ex: In a company many employees are associated with
multiple projects(completed/existing), and at the same
time, projects are associated with multiple employees.
Question
1. 1-1
2. 1-M
3. M-N
Question
1. 1-1
2. 1-M
3. M-N
Question
1. 1-1
2. 1-M
3. M-N
Glossary of Terms
Schema
•A structure that contains descriptions of objects
created by a user, such as base tables, views, and
constraints, as part of a database
Base table
•A table in the relational data model containing the
inserted raw data. Base tables correspond to the
relations that are identified in the database’s
conceptual schema
Constraint
•A rule that cannot be violated by database users
Questions
References
• Hoffer, J.A., Ramesh, v., and Topi, H. (2013). Modern
Database Management. 11th ed. ISBN 978-0-13-266225-3
• Kroenke, D. M. (2006). Database Processing:
Fundamentals, design, and implementation. Pearson
Prentice Hall. New Jersey.
Web
• http://dev.mysql.com/doc/refman/5.7/en/mysql-clusteroverview.html
• https://sites.google.com/site/kittirak/mysql-cluster/bththi-2-rucak-kab-mysql-cluster
• https://www.digitalocean.com/community/tutorials/howto-create-a-multi-node-mysql-cluster-on-ubuntu-16-04
• http://ewebarchitecture.com/web-databases/refineddatabase-relationships