SlideShare a Scribd company logo
Fakultas Ilmu Komputer - Universitas Indonesia
Slide 2
The Relational Data Model and Relational
Database Constraints
BASIS DATA
Semester Ganjil 2015 / 2016
2
These slides are a modification to the supplementary slide of
“Database System”, 6th edition, Elmasri/Navathe, 2011:
Chapter 3 The Relational Data Model and Relational
Database Constraints
Basis Data Ganjil 2015/2016
3
Outline
 Relational Model Concept
 Characteristics of Relations
 Relational Model Notation
 Relational Model Constraints
 Update Operations, Transactions, and Dealing with
Constraint Violations
Basis Data Ganjil 2015/2016
4
The Relational Data Model
 Relational model
 Introduced by Ted Codd of IBM Research in 1970
 The model uses the concept of a mathematical relation
 First commercial implementations available in early 1980s
 Has been implemented in a large number of commercial
system
 Popular Relational DBMS: Oracle, DB2, MySQL, PostgreSQL
 Hierarchical and network models
 Preceded the relational model
Basis Data Ganjil 2015/2016
5
Relational Model Concepts
 Represents data as a collection of relations
 Table of values
 Row
• Represents a collection of related data values
• Fact that typically corresponds to a real-world entity or relationship
• Tuple
 Table name and column names
• Interpret the meaning of the values in each row attribute
Basis Data Ganjil 2015/2016
6
Relational Model Concepts (cont’d.)
Basis Data Ganjil 2015/2016
7
Domains, Attributes, Tuples, and Relations
 Domain D
 Set of atomic values
 Example:
 GPA: real number between 0 and 4
 Atomic
 Each value indivisible
 Specifying a domain
 Data type specified for each domain
Basis Data Ganjil 2015/2016
8
Domains, Attributes, Tuples, and Relations (cont’d.)
 Relation schema R
 Denoted by R(A1, A2, ...,An)
 Made up of a relation name R and a list of attributes, A1, A2, ...,
An
 Example: STUDENT(Name, SSN, Home_phone, Address,
Office_phone, Age, Gpa)
 Attribute Ai
 Name of a role played by some domain D in the relation
schema R
 Degree (or arity) of a relation
 Number of attributes n of its relation schema
 STUDENT: a relation of degree 7
Basis Data Ganjil 2015/2016
9
Domains, Attributes, Tuples, and Relations (cont’d.)
 Relation (or relation state)
 Set of n-tuples r = {t1, t2, ..., tn}
 Each n-tuple t
• Ordered list of n values t =<v1, v2, ..., vn >
• Each value vi, 1 ≤ i ≤ n, is an element of dom(Ai) or is a special NULL
value
• Example:
• t = <‘Benyamin Bayer’, ‘305-61-2435’, …, 3.21>
Basis Data Ganjil 2015/2016
10
Domains, Attributes, Tuples, and Relations (cont’d.)
 Relation (or relation state) r(R)
 Mathematical relation of degree n on the domains dom(A1),
dom(A2), ..., dom(An)
 Subset of the Cartesian product of the domains that define R:
• r(R) ⊆ (dom(A1) × dom(A2) × ... × dom(An))
Basis Data Ganjil 2015/2016
11
Example
 Given relation schema R(A1, A2)
 dom(A1) = {0,1}
 dom(A2) = {a,b,c}
 Cartesian product of the domain  dom (A1) X dom (A2):
{<0,a> , <0,b> , <0,c>, <1,a>, <1,b>, <1,c> }
 A state of R:
{<0,a> , <1,a>, <1,c> }
Basis Data Ganjil 2015/2016
12
Domains, Attributes, Tuples, and Relations (cont’d.)
 Cardinality
 Total number of values in domain
 Current relation state
 Relation state at a given time
 Reflects only the valid tuples that represent a particular state
of the real world
 Attribute names
 Indicate different roles, or interpretations, for the domain
Basis Data Ganjil 2015/2016
13
Equivalent Terminology
Basis Data Ganjil 2015/2016
Formal (Relational Model)
Relation
Tuple
Attribute
Non Formal
Table (File)
Row (Record)
Column Header (Field)
Domain
Schema of a relation
State of the relation
All possible column values
Table definition
Populated table
14
Outline
 The Relational Data Model
 Characteristics of Relations
 Relational Model Notation
 Relational Model Constraints
 Update Operations, Transactions, and Dealing with
Constraint Violations
Basis Data Ganjil 2015/2016
15
Characteristics of Relations
 Ordering of tuples in a relation
 Relation defined as a set of tuples
 Elements have no order among them
Basis Data Ganjil 2015/2016
16
Characteristics of Relations
 Ordering of values within a tuple
 Order of attributes and values is not that important
 As long as correspondence between attributes and values
maintained
 Alternative definition of a relation
 Tuple considered as a set of (<attribute>, <value>) pairs
 Each pair gives the value of the mapping from an attribute Ai
to a value vi from dom(Ai)
Basis Data Ganjil 2015/2016
17
Characteristics of Relations (cont’d.)
 Use the first definition of relation
 Attributes and the values within tuples are ordered
 Simpler notation
Basis Data Ganjil 2015/2016
18
Characteristics of Relations (cont’d.)
 Values in tuples
 Each value in a tuple is atomic
 Flat relational model
• Composite and multivalued attributes not allowed
• First normal form assumption
 Multivalued attributes
 Example: Favourite color = {red, green}
• Must be represented by separate relations
 Composite attributes
 Example: Address can be divided into Street_address, City, State, Zip.
• Represented only by simple component attributes in basic relational
model
Basis Data Ganjil 2015/2016
19
Characteristics of Relations (cont’d.)
 NULL values
 Represent the values of attributes that may be unknown or
may not apply to a tuple
 Meanings for NULL values
• Value unknown
• Value exists but is not available
• Attribute does not apply to this tuple (also known as value undefined)
Basis Data Ganjil 2015/2016
20
Characteristics of Relations (cont’d.)
 Interpretation (meaning) of a relation schema
 Assertion
For example, the schema of the STUDENT asserts that, in general, a student entity
has a Name, Ssn, Home_phone, Address, Office_phone, Age, and Gpa
• Each tuple in the relation is a fact or a particular instance of
the assertion
• STUDENT whose Name is Benjamin Bayer, Ssn is 305-61-2435, Age is 19, and
so on.
 Predicate
• Values in each tuple interpreted as values that satisfy predicate
the predicate STUDENT (Name, Ssn, ...) is true for the five tuples in relation STUDENT
Basis Data Ganjil 2015/2016
21
Exercise
From the following tables, which one is a relation in a
relational database?
Basis Data Ganjil 2015/2016
R3
A B C D
a2 {b1, b2} c1 d5
a2 b7 c9 d5
a2 b23 c22 d1
…...
A B C D
a2 b2 c6 d1
a2 b7 c9 d5
a2 b7 c9 d5
…...
R1 R2
E# Ename AGE ADDRESS
E1 Smith 30 3302 Peachtree Rd., Atlanta, GA
E2 Diamond 45 1888 Buford Hyw.
E3 Evan Baker Ct. Atlanta
22
Outline
 The Relational Data Model
 Characteristics of Relations
 Relational Model Notation
 Relational Model Constraints
 Update Operations, Transactions, and Dealing with
Constraint Violations
Basis Data Ganjil 2015/2016
23
Relational Model Notation
 Relation schema R of degree n
 Denoted by R(A1, A2, ..., An)
 Uppercase letters Q, R, S
 Denote relation names
 Lowercase letters q, r, s
 Denote relation states
 Letters t, u, v
 Denote tuples
Basis Data Ganjil 2015/2016
24
Relational Model Notation
 Name of a relation schema: STUDENT
 Indicates the current set of tuples in that relation
 Notation: STUDENT(Name, Ssn, ...)
 Refers only to relation schema
 Attribute A can be qualified with the relation name R to
which it belongs
 Using the dot notation R.A
Basis Data Ganjil 2015/2016
25
Relational Model Notation
 n-tuple t in a relation r(R)
 Denoted by t = <v1, v2, ..., vn>
 vi is the value corresponding to attribute Ai
 Component values of tuples:
 t[Ai] and t.Ai refer to the value vi in t for attribute Ai
 t[Au, Aw, ..., Az] and t.(Au, Aw, ..., Az) refer to the subtuple of
values <vu, vw, ..., vz> from t corresponding to the attributes
specified in the list
 Example:
t = <‘Barbara Benson’, ‘533-69-1238’, ‘(817)839-8461’, ‘738 Fontana Lane’, NULL, 19, 3.25>
from the STUDENT
t*Name+ = <‘Barbara Benson’>, and t*Ssn, Gpa, Age+ = <‘533-69-1238’,3.25, 19>.
Basis Data Ganjil 2015/2016
26
Outline
 The Relational Data Model
 Characteristics of Relations
 Relational Model Notation
 Relational Model Constraints
 Update Operations, Transactions, and Dealing with
Constraint Violations
Basis Data Ganjil 2015/2016
27
Relational Model Constraints
 Constraints
 Restrictions on the actual values in a database state
 Derived from the rules in the miniworld that the database
represents
 Constraints Categories:
 Inherent model-based constraints or implicit constraints
 Inherent in the data model
 Schema-based constraints or explicit constraints
 Can be directly expressed in schemas of the data model
 Application-based or semantic constraints or business rules
 Cannot be directly expressed in schemas
 Expressed and enforced by application program
Basis Data Ganjil 2015/2016
28
Classification of Relational Integrity Constraints
Basis Data Ganjil 2015/2016
Key Constraints
Referential Integrity Constraints
Entity Integrity ConstraintsMain
Domain Constraints
State Constraints
Transition ConstraintsOthers
(Semantic)
29
Domain Constraints
 Specify that within each tuple, the value of each attribute
A must be an atomic value from the domain dom(A)
 Typically include:
 Numeric data types for integers and real numbers
 Characters
 Booleans
 Fixed-length strings
 Variable-length strings
 Date, time, timestamp
 Money
 Other special data types
Basis Data Ganjil 2015/2016
30
Key Constraints and Constraints on NULL Values
 Key Constraints
 No two tuples can have the same combination of values for all
their attributes.
 Superkey (SK)
 SK: an attribute or set of attributes that guarantee that no two
distinct tuples in any state r of R can have the same value for
SK
Basis Data Ganjil 2015/2016
31
Key Constraints and Constraints on NULL Values
(cont’d.)
 Key
 Superkey of R
 Removing any attribute A from K leaves a set of attributes K
that is not a superkey of R any more
 Key satisfies two properties:
 Two distinct tuples in any state of relation cannot have
identical values for (all) attributes in key
 Minimal superkey
• Cannot remove any attributes and still have uniqueness constraint in
above condition hold
Basis Data Ganjil 2015/2016
32
Key Constraints and Constraints on NULL Values
(cont’d.)
 Candidate key
 Relation schema may have more than one key
 Primary key of the relation
 Designated among candidate keys
 Underline attribute
 Other candidate keys are designated as unique keys /
alternate keys
Basis Data Ganjil 2015/2016
33
Key Constraints and Constraints on NULL Values
(cont’d.)
34
Example
SSN FName LName BirthDate Sex Address
0606007800 Ahmad Zakky 10-4-87 L Jakarta
0607001123 Gede Saraswati 19-9-87 P Denpasar
0607120012 Bayu Wirawan 12-12-86 L Jimbaran
0607121023 Satya Wirawan 12-12-86 L Jimbaran
0607131240 Fira Bahira 1-3-87 P Jakarta
0607132222 Nayla Putri 1-9-86 P Depok
Basis Data Ganjil 2015/2016
Candidate key:
SSN,
FName
Primary Key:
SSN
Alternate Key:
FName
Super key:
SSN,
{SSN, Lname},
{FName, BirthDate},
{FName, Sex},
…
35
Key Constraints and Constraints on NULL Values
(cont’d.)
 Constraints on NULL Value
 For an attribute, we can specify whether NULL values are or
are not permitted
 For example: every STUDENT tuple must have a valid, non-
NULL value for the Name attribute  then Name of STUDENT
is constraint to be NOT NULL
Basis Data Ganjil 2015/2016
36
Relational Databases and Relational Database
Schemas
 Relational database schema S
 Set of relation schemas S = {R1, R2, ..., Rm}
 Set of integrity constraints IC
 Relational database state
 Set of relation states DB = {r1, r2, ..., rm}
 Each ri is a state of Ri and such that the ri relation states satisfy
integrity constraints specified in IC
Basis Data Ganjil 2015/2016
37
Relational Databases and Relational Database
Schemas (cont’d.)
Basis Data Ganjil 2015/2016
38
Basis Data Ganjil 2015/2016
39
Relational Databases and Relational Database
Schemas (cont’d.)
 Invalid state
 Does not obey all the integrity constraints
 Valid state
 Satisfies all the constraints in the defined set of integrity
constraints IC
Basis Data Ganjil 2015/2016
40
Integrity, Referential Integrity,
and Foreign Keys
 Entity integrity constraint
 No primary key value can be NULL
 Referential integrity constraint
 Specified between two relations
 Maintains consistency among tuples in two relations
Basis Data Ganjil 2015/2016
41
Integrity, Referential Integrity,
and Foreign Keys (cont’d.)
Basis Data Ganjil 2015/2016
42
Integrity, Referential Integrity,
and Foreign Keys (cont’d.)
 Foreign key rules:
 The attributes in FK have the same domain(s) as the primary
key attributes PK
 Value of FK in a tuple t1 of the current state r1(R1) either occurs
as a value of PK for some tuple t2 in the current state r2(R2) or
is NULL
Basis Data Ganjil 2015/2016
43
Integrity, Referential Integrity,
and Foreign Keys (cont’d.)
 Diagrammatically display referential integrity constraints
 Directed arc from each foreign key to the relation it references
 All integrity constraints should be specified on relational
database schema
Basis Data Ganjil 2015/2016
44
Other Types of Constraints
 Semantic integrity constraints
 May have to be specified and enforced on a relational
database
 Use triggers and assertions
 More common to check for these types of constraints within
the application programs
Basis Data Ganjil 2015/2016
46
Latihan
 Basis data yang memproses order (pemesanan) pada sebuah perusahaan
memiliki 6 relasi berikut:
CUSTOMER (Cust#, Cname, City)
ORDER (Order#, Odate, Cust#, Ord_Amt)
ORDER_ITEM (Order#, Item#, Qty)
ITEM (Item#, Unit_price)
SHIPMENT (Order#, Warehouse#, Ship_date)
WAREHOUSE (Warehouse#, City)
Ord_Amt mengacu pada jumlah harga pada satu kali order. Odate
menyatakan tanggal pemesanan dilakukan, Ship_date menyatakan tanggal
pengiriman barang yang dipesan customer dari gudang. Asumsikan bahwa
suatu order dapat mengambil barang dari beberapa gudang (warehouse).
Nyatakan foreign key yang mungkin untuk skema basis data ini.
Basis Data Ganjil 2015/2016
47
Outline
 The Relational Data Model
 Characteristics of Relations
 Relational Model Notation
 Relational Model Constraints
 Update Operations, Transactions, and Dealing
with Constraint Violations
Basis Data Ganjil 2015/2016
48
Update Operations, Transactions, and Dealing
with Constraint Violations
 Operations of the relational model can be categorized
into retrievals and updates
 Basic operations that change the states of relations in the
database:
 Insert
 Delete
 Update (or Modify)
Basis Data Ganjil 2015/2016
49
Basis Data Ganjil 2015/2016
50
Basis Data Ganjil 2015/2016
51
The Insert Operation
 Provides a list of attribute values for a new tuple t that is
to be inserted into a relation R
 Can violate any of the four types of constraints
 If an insertion violates one or more constraints
 Default option is to reject the insertion
Basis Data Ganjil 2015/2016
52
The Delete Operation
 Can violate only referential integrity
 If tuple being deleted is referenced by foreign keys from other
tuples
 Restrict
• Reject the deletion
 Cascade
• Propagate the deletion by deleting tuples that reference the tuple
that is being deleted
 Set null or set default
• Modify the referencing attribute values that cause the violation
Basis Data Ganjil 2015/2016
53
The Update Operation
 Necessary to specify a condition on attributes of relation
 Select the tuple (or tuples) to be modified
 If attribute not part of a primary key nor of a foreign key
 Usually causes no problems
 Updating a primary/foreign key
 Similar issues as with Insert/Delete
Basis Data Ganjil 2015/2016
54
The Transaction Concept
 Transaction
 Executing program
 Includes some database operations
 Must leave the database in a valid or consistent state
 Online transaction processing (OLTP) systems
 Execute transactions at rates that reach several hundred per
second
Basis Data Ganjil 2015/2016
55
Latihan
Basis Data Ganjil 2015/2016
Apakah ada constraints yang
dilanggar pada operasi
berikut?
1. Insert < 'ProductA', 4,
'Bellaire', 2 > into PROJECT.
2. Insert < '677678989', null,
'40.0' > into WORKS_ON.
3. Delete the WORKS_ON
tuples with ESSN=
'333445555'.
4. Delete the EMPLOYEE tuple
with SSN= '987654321'.
5. Modify the SUPERSSN
attribute of the EMPLOYEE
tuple with SSN= '999887777'
to '943775543'.
56
Summary
 Characteristics differentiate relations from ordinary tables
or files
 Classify database constraints into:
 Inherent model-based constraints, explicit schema-based
constraints, and application-based constraints
 Modification operations on the relational model:
 Insert, Delete, and Update
Basis Data Ganjil 2015/2016
57
FINISH
Basis Data Ganjil 2015/2016

More Related Content

What's hot

Tableau (BI) interview questions version 2.0
Tableau (BI) interview questions version 2.0Tableau (BI) interview questions version 2.0
Tableau (BI) interview questions version 2.0
Visualect
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
Guy Lebanon
 
What are Parameters in Tableau | Tableau Tutorial | Edureka
What are Parameters in Tableau | Tableau Tutorial | EdurekaWhat are Parameters in Tableau | Tableau Tutorial | Edureka
What are Parameters in Tableau | Tableau Tutorial | Edureka
Edureka!
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
sunanditaAnand
 
Data Warehouse Architecture
Data Warehouse ArchitectureData Warehouse Architecture
Data Warehouse Architecturepcherukumalla
 
BPC 10.1 basics
BPC 10.1 basicsBPC 10.1 basics
BPC 10.1 basics
kamal ega
 
Power BI On AIR - Melissa Coates: "What You Need to Know to Administer Power BI"
Power BI On AIR - Melissa Coates: "What You Need to Know to Administer Power BI"Power BI On AIR - Melissa Coates: "What You Need to Know to Administer Power BI"
Power BI On AIR - Melissa Coates: "What You Need to Know to Administer Power BI"
Bohdan Maherus
 
integrity constraints
integrity constraintsintegrity constraints
integrity constraints
madhav bansal
 
Chapter-4 Enhanced ER Model
Chapter-4 Enhanced ER ModelChapter-4 Enhanced ER Model
Chapter-4 Enhanced ER Model
Kunal Anand
 
03 Modelo Relacional
03 Modelo Relacional03 Modelo Relacional
03 Modelo Relacional
Kudos S.A.S
 
Presentacion pasaje a tablas
Presentacion pasaje a tablasPresentacion pasaje a tablas
Presentacion pasaje a tablas
Bruno Gómez Hernández
 
Tableau data terminology
Tableau   data terminologyTableau   data terminology
Tableau data terminology
Learnbay Datascience
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMSkoolkampus
 
Sap BPC concepts
Sap BPC conceptsSap BPC concepts
Sap BPC concepts
Verity Solutions
 
Joins in databases
Joins in databases Joins in databases
Joins in databases
CourseHunt
 
Fundamentals of Data Modeling and Database Design by Dr. Kamal Gulati
Fundamentals of Data Modeling and Database Design by Dr. Kamal GulatiFundamentals of Data Modeling and Database Design by Dr. Kamal Gulati
Fundamentals of Data Modeling and Database Design by Dr. Kamal Gulati
Amity University | FMS - DU | IMT | Stratford University | KKMI International Institute | AIMA | DTU
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
String function in my sql
String function in my sqlString function in my sql
String function in my sql
knowledgemart
 

What's hot (20)

Tableau (BI) interview questions version 2.0
Tableau (BI) interview questions version 2.0Tableau (BI) interview questions version 2.0
Tableau (BI) interview questions version 2.0
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
What are Parameters in Tableau | Tableau Tutorial | Edureka
What are Parameters in Tableau | Tableau Tutorial | EdurekaWhat are Parameters in Tableau | Tableau Tutorial | Edureka
What are Parameters in Tableau | Tableau Tutorial | Edureka
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Data Warehouse Architecture
Data Warehouse ArchitectureData Warehouse Architecture
Data Warehouse Architecture
 
BPC 10.1 basics
BPC 10.1 basicsBPC 10.1 basics
BPC 10.1 basics
 
SAP BI Overview
SAP BI OverviewSAP BI Overview
SAP BI Overview
 
Power BI On AIR - Melissa Coates: "What You Need to Know to Administer Power BI"
Power BI On AIR - Melissa Coates: "What You Need to Know to Administer Power BI"Power BI On AIR - Melissa Coates: "What You Need to Know to Administer Power BI"
Power BI On AIR - Melissa Coates: "What You Need to Know to Administer Power BI"
 
integrity constraints
integrity constraintsintegrity constraints
integrity constraints
 
Chapter-4 Enhanced ER Model
Chapter-4 Enhanced ER ModelChapter-4 Enhanced ER Model
Chapter-4 Enhanced ER Model
 
03 Modelo Relacional
03 Modelo Relacional03 Modelo Relacional
03 Modelo Relacional
 
Presentacion pasaje a tablas
Presentacion pasaje a tablasPresentacion pasaje a tablas
Presentacion pasaje a tablas
 
Tableau data terminology
Tableau   data terminologyTableau   data terminology
Tableau data terminology
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS
 
Sap BPC concepts
Sap BPC conceptsSap BPC concepts
Sap BPC concepts
 
Joins in databases
Joins in databases Joins in databases
Joins in databases
 
Fundamentals of Data Modeling and Database Design by Dr. Kamal Gulati
Fundamentals of Data Modeling and Database Design by Dr. Kamal GulatiFundamentals of Data Modeling and Database Design by Dr. Kamal Gulati
Fundamentals of Data Modeling and Database Design by Dr. Kamal Gulati
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
String function in my sql
String function in my sqlString function in my sql
String function in my sql
 

Viewers also liked

Huruf a ha fathah slide
Huruf a ha fathah   slideHuruf a ha fathah   slide
Huruf a ha fathah slide
Dika Handika
 
adab makan
adab makanadab makan
adab makan
Siti Nurwahida
 
Pendidikan Islam: Hukum Tajwid
Pendidikan Islam: Hukum TajwidPendidikan Islam: Hukum Tajwid
Pendidikan Islam: Hukum Tajwid
LittleBieb12
 
Hukum tajwid
Hukum tajwidHukum tajwid
Hukum tajwid
Siti Nadrah Hasnan
 

Viewers also liked (6)

Huruf a ha fathah slide
Huruf a ha fathah   slideHuruf a ha fathah   slide
Huruf a ha fathah slide
 
adab makan
adab makanadab makan
adab makan
 
Hukum tajwid
Hukum tajwidHukum tajwid
Hukum tajwid
 
Pendidikan Islam: Hukum Tajwid
Pendidikan Islam: Hukum TajwidPendidikan Islam: Hukum Tajwid
Pendidikan Islam: Hukum Tajwid
 
Hukum tajwid
Hukum tajwidHukum tajwid
Hukum tajwid
 
Ilmu Tajwid
Ilmu TajwidIlmu Tajwid
Ilmu Tajwid
 

Similar to 2. relational model_150903

4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
LPhct2
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 
DBMS Unit-2.pdf
DBMS Unit-2.pdfDBMS Unit-2.pdf
DBMS Unit-2.pdf
vaishnavi339314
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
Mustafa Kamel Mohammadi
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptx
ThangamaniR3
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
Raj vardhan
 
Relational model
Relational modelRelational model
Relational model
Dabbal Singh Mahara
 
Relational Model on Database management PPT
Relational Model on Database management PPTRelational Model on Database management PPT
Relational Model on Database management PPT
ssuser3e0f731
 
The relational data model part[1]
The relational data model part[1]The relational data model part[1]
The relational data model part[1]
Bashir Rezaie
 
Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013
Prosanta Ghosh
 
Data model
Data modelData model
Data model
Syed Zaid Irshad
 
Relational model
Relational modelRelational model
Relational model
RUpaliLohar
 
Relational model
Relational modelRelational model
Relational model
RUpaliLohar
 
3 relational model
3 relational model3 relational model
3 relational model
Utkarsh De
 
Chapter05db
Chapter05dbChapter05db
Chapter05db
abhilashbachu5
 
Chapter05 Data Base Chapter05 Data Base .pdf
Chapter05 Data Base  Chapter05 Data Base  .pdfChapter05 Data Base  Chapter05 Data Base  .pdf
Chapter05 Data Base Chapter05 Data Base .pdf
mohammedabomashowrms
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
SrikanthS494888
 
RDBMS
RDBMSRDBMS
RDBMS
NilaNila16
 

Similar to 2. relational model_150903 (20)

4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
DBMS Unit-2.pdf
DBMS Unit-2.pdfDBMS Unit-2.pdf
DBMS Unit-2.pdf
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptx
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
 
Relational model
Relational modelRelational model
Relational model
 
Relational Model on Database management PPT
Relational Model on Database management PPTRelational Model on Database management PPT
Relational Model on Database management PPT
 
The relational data model part[1]
The relational data model part[1]The relational data model part[1]
The relational data model part[1]
 
Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013
 
Data model
Data modelData model
Data model
 
Relational model
Relational modelRelational model
Relational model
 
Relational model
Relational modelRelational model
Relational model
 
3 relational model
3 relational model3 relational model
3 relational model
 
Chapter05db
Chapter05dbChapter05db
Chapter05db
 
Chapter05 Data Base Chapter05 Data Base .pdf
Chapter05 Data Base  Chapter05 Data Base  .pdfChapter05 Data Base  Chapter05 Data Base  .pdf
Chapter05 Data Base Chapter05 Data Base .pdf
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
RDBMS
RDBMSRDBMS
RDBMS
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 

2. relational model_150903

  • 1. Fakultas Ilmu Komputer - Universitas Indonesia Slide 2 The Relational Data Model and Relational Database Constraints BASIS DATA Semester Ganjil 2015 / 2016
  • 2. 2 These slides are a modification to the supplementary slide of “Database System”, 6th edition, Elmasri/Navathe, 2011: Chapter 3 The Relational Data Model and Relational Database Constraints Basis Data Ganjil 2015/2016
  • 3. 3 Outline  Relational Model Concept  Characteristics of Relations  Relational Model Notation  Relational Model Constraints  Update Operations, Transactions, and Dealing with Constraint Violations Basis Data Ganjil 2015/2016
  • 4. 4 The Relational Data Model  Relational model  Introduced by Ted Codd of IBM Research in 1970  The model uses the concept of a mathematical relation  First commercial implementations available in early 1980s  Has been implemented in a large number of commercial system  Popular Relational DBMS: Oracle, DB2, MySQL, PostgreSQL  Hierarchical and network models  Preceded the relational model Basis Data Ganjil 2015/2016
  • 5. 5 Relational Model Concepts  Represents data as a collection of relations  Table of values  Row • Represents a collection of related data values • Fact that typically corresponds to a real-world entity or relationship • Tuple  Table name and column names • Interpret the meaning of the values in each row attribute Basis Data Ganjil 2015/2016
  • 6. 6 Relational Model Concepts (cont’d.) Basis Data Ganjil 2015/2016
  • 7. 7 Domains, Attributes, Tuples, and Relations  Domain D  Set of atomic values  Example:  GPA: real number between 0 and 4  Atomic  Each value indivisible  Specifying a domain  Data type specified for each domain Basis Data Ganjil 2015/2016
  • 8. 8 Domains, Attributes, Tuples, and Relations (cont’d.)  Relation schema R  Denoted by R(A1, A2, ...,An)  Made up of a relation name R and a list of attributes, A1, A2, ..., An  Example: STUDENT(Name, SSN, Home_phone, Address, Office_phone, Age, Gpa)  Attribute Ai  Name of a role played by some domain D in the relation schema R  Degree (or arity) of a relation  Number of attributes n of its relation schema  STUDENT: a relation of degree 7 Basis Data Ganjil 2015/2016
  • 9. 9 Domains, Attributes, Tuples, and Relations (cont’d.)  Relation (or relation state)  Set of n-tuples r = {t1, t2, ..., tn}  Each n-tuple t • Ordered list of n values t =<v1, v2, ..., vn > • Each value vi, 1 ≤ i ≤ n, is an element of dom(Ai) or is a special NULL value • Example: • t = <‘Benyamin Bayer’, ‘305-61-2435’, …, 3.21> Basis Data Ganjil 2015/2016
  • 10. 10 Domains, Attributes, Tuples, and Relations (cont’d.)  Relation (or relation state) r(R)  Mathematical relation of degree n on the domains dom(A1), dom(A2), ..., dom(An)  Subset of the Cartesian product of the domains that define R: • r(R) ⊆ (dom(A1) × dom(A2) × ... × dom(An)) Basis Data Ganjil 2015/2016
  • 11. 11 Example  Given relation schema R(A1, A2)  dom(A1) = {0,1}  dom(A2) = {a,b,c}  Cartesian product of the domain  dom (A1) X dom (A2): {<0,a> , <0,b> , <0,c>, <1,a>, <1,b>, <1,c> }  A state of R: {<0,a> , <1,a>, <1,c> } Basis Data Ganjil 2015/2016
  • 12. 12 Domains, Attributes, Tuples, and Relations (cont’d.)  Cardinality  Total number of values in domain  Current relation state  Relation state at a given time  Reflects only the valid tuples that represent a particular state of the real world  Attribute names  Indicate different roles, or interpretations, for the domain Basis Data Ganjil 2015/2016
  • 13. 13 Equivalent Terminology Basis Data Ganjil 2015/2016 Formal (Relational Model) Relation Tuple Attribute Non Formal Table (File) Row (Record) Column Header (Field) Domain Schema of a relation State of the relation All possible column values Table definition Populated table
  • 14. 14 Outline  The Relational Data Model  Characteristics of Relations  Relational Model Notation  Relational Model Constraints  Update Operations, Transactions, and Dealing with Constraint Violations Basis Data Ganjil 2015/2016
  • 15. 15 Characteristics of Relations  Ordering of tuples in a relation  Relation defined as a set of tuples  Elements have no order among them Basis Data Ganjil 2015/2016
  • 16. 16 Characteristics of Relations  Ordering of values within a tuple  Order of attributes and values is not that important  As long as correspondence between attributes and values maintained  Alternative definition of a relation  Tuple considered as a set of (<attribute>, <value>) pairs  Each pair gives the value of the mapping from an attribute Ai to a value vi from dom(Ai) Basis Data Ganjil 2015/2016
  • 17. 17 Characteristics of Relations (cont’d.)  Use the first definition of relation  Attributes and the values within tuples are ordered  Simpler notation Basis Data Ganjil 2015/2016
  • 18. 18 Characteristics of Relations (cont’d.)  Values in tuples  Each value in a tuple is atomic  Flat relational model • Composite and multivalued attributes not allowed • First normal form assumption  Multivalued attributes  Example: Favourite color = {red, green} • Must be represented by separate relations  Composite attributes  Example: Address can be divided into Street_address, City, State, Zip. • Represented only by simple component attributes in basic relational model Basis Data Ganjil 2015/2016
  • 19. 19 Characteristics of Relations (cont’d.)  NULL values  Represent the values of attributes that may be unknown or may not apply to a tuple  Meanings for NULL values • Value unknown • Value exists but is not available • Attribute does not apply to this tuple (also known as value undefined) Basis Data Ganjil 2015/2016
  • 20. 20 Characteristics of Relations (cont’d.)  Interpretation (meaning) of a relation schema  Assertion For example, the schema of the STUDENT asserts that, in general, a student entity has a Name, Ssn, Home_phone, Address, Office_phone, Age, and Gpa • Each tuple in the relation is a fact or a particular instance of the assertion • STUDENT whose Name is Benjamin Bayer, Ssn is 305-61-2435, Age is 19, and so on.  Predicate • Values in each tuple interpreted as values that satisfy predicate the predicate STUDENT (Name, Ssn, ...) is true for the five tuples in relation STUDENT Basis Data Ganjil 2015/2016
  • 21. 21 Exercise From the following tables, which one is a relation in a relational database? Basis Data Ganjil 2015/2016 R3 A B C D a2 {b1, b2} c1 d5 a2 b7 c9 d5 a2 b23 c22 d1 …... A B C D a2 b2 c6 d1 a2 b7 c9 d5 a2 b7 c9 d5 …... R1 R2 E# Ename AGE ADDRESS E1 Smith 30 3302 Peachtree Rd., Atlanta, GA E2 Diamond 45 1888 Buford Hyw. E3 Evan Baker Ct. Atlanta
  • 22. 22 Outline  The Relational Data Model  Characteristics of Relations  Relational Model Notation  Relational Model Constraints  Update Operations, Transactions, and Dealing with Constraint Violations Basis Data Ganjil 2015/2016
  • 23. 23 Relational Model Notation  Relation schema R of degree n  Denoted by R(A1, A2, ..., An)  Uppercase letters Q, R, S  Denote relation names  Lowercase letters q, r, s  Denote relation states  Letters t, u, v  Denote tuples Basis Data Ganjil 2015/2016
  • 24. 24 Relational Model Notation  Name of a relation schema: STUDENT  Indicates the current set of tuples in that relation  Notation: STUDENT(Name, Ssn, ...)  Refers only to relation schema  Attribute A can be qualified with the relation name R to which it belongs  Using the dot notation R.A Basis Data Ganjil 2015/2016
  • 25. 25 Relational Model Notation  n-tuple t in a relation r(R)  Denoted by t = <v1, v2, ..., vn>  vi is the value corresponding to attribute Ai  Component values of tuples:  t[Ai] and t.Ai refer to the value vi in t for attribute Ai  t[Au, Aw, ..., Az] and t.(Au, Aw, ..., Az) refer to the subtuple of values <vu, vw, ..., vz> from t corresponding to the attributes specified in the list  Example: t = <‘Barbara Benson’, ‘533-69-1238’, ‘(817)839-8461’, ‘738 Fontana Lane’, NULL, 19, 3.25> from the STUDENT t*Name+ = <‘Barbara Benson’>, and t*Ssn, Gpa, Age+ = <‘533-69-1238’,3.25, 19>. Basis Data Ganjil 2015/2016
  • 26. 26 Outline  The Relational Data Model  Characteristics of Relations  Relational Model Notation  Relational Model Constraints  Update Operations, Transactions, and Dealing with Constraint Violations Basis Data Ganjil 2015/2016
  • 27. 27 Relational Model Constraints  Constraints  Restrictions on the actual values in a database state  Derived from the rules in the miniworld that the database represents  Constraints Categories:  Inherent model-based constraints or implicit constraints  Inherent in the data model  Schema-based constraints or explicit constraints  Can be directly expressed in schemas of the data model  Application-based or semantic constraints or business rules  Cannot be directly expressed in schemas  Expressed and enforced by application program Basis Data Ganjil 2015/2016
  • 28. 28 Classification of Relational Integrity Constraints Basis Data Ganjil 2015/2016 Key Constraints Referential Integrity Constraints Entity Integrity ConstraintsMain Domain Constraints State Constraints Transition ConstraintsOthers (Semantic)
  • 29. 29 Domain Constraints  Specify that within each tuple, the value of each attribute A must be an atomic value from the domain dom(A)  Typically include:  Numeric data types for integers and real numbers  Characters  Booleans  Fixed-length strings  Variable-length strings  Date, time, timestamp  Money  Other special data types Basis Data Ganjil 2015/2016
  • 30. 30 Key Constraints and Constraints on NULL Values  Key Constraints  No two tuples can have the same combination of values for all their attributes.  Superkey (SK)  SK: an attribute or set of attributes that guarantee that no two distinct tuples in any state r of R can have the same value for SK Basis Data Ganjil 2015/2016
  • 31. 31 Key Constraints and Constraints on NULL Values (cont’d.)  Key  Superkey of R  Removing any attribute A from K leaves a set of attributes K that is not a superkey of R any more  Key satisfies two properties:  Two distinct tuples in any state of relation cannot have identical values for (all) attributes in key  Minimal superkey • Cannot remove any attributes and still have uniqueness constraint in above condition hold Basis Data Ganjil 2015/2016
  • 32. 32 Key Constraints and Constraints on NULL Values (cont’d.)  Candidate key  Relation schema may have more than one key  Primary key of the relation  Designated among candidate keys  Underline attribute  Other candidate keys are designated as unique keys / alternate keys Basis Data Ganjil 2015/2016
  • 33. 33 Key Constraints and Constraints on NULL Values (cont’d.)
  • 34. 34 Example SSN FName LName BirthDate Sex Address 0606007800 Ahmad Zakky 10-4-87 L Jakarta 0607001123 Gede Saraswati 19-9-87 P Denpasar 0607120012 Bayu Wirawan 12-12-86 L Jimbaran 0607121023 Satya Wirawan 12-12-86 L Jimbaran 0607131240 Fira Bahira 1-3-87 P Jakarta 0607132222 Nayla Putri 1-9-86 P Depok Basis Data Ganjil 2015/2016 Candidate key: SSN, FName Primary Key: SSN Alternate Key: FName Super key: SSN, {SSN, Lname}, {FName, BirthDate}, {FName, Sex}, …
  • 35. 35 Key Constraints and Constraints on NULL Values (cont’d.)  Constraints on NULL Value  For an attribute, we can specify whether NULL values are or are not permitted  For example: every STUDENT tuple must have a valid, non- NULL value for the Name attribute  then Name of STUDENT is constraint to be NOT NULL Basis Data Ganjil 2015/2016
  • 36. 36 Relational Databases and Relational Database Schemas  Relational database schema S  Set of relation schemas S = {R1, R2, ..., Rm}  Set of integrity constraints IC  Relational database state  Set of relation states DB = {r1, r2, ..., rm}  Each ri is a state of Ri and such that the ri relation states satisfy integrity constraints specified in IC Basis Data Ganjil 2015/2016
  • 37. 37 Relational Databases and Relational Database Schemas (cont’d.) Basis Data Ganjil 2015/2016
  • 38. 38 Basis Data Ganjil 2015/2016
  • 39. 39 Relational Databases and Relational Database Schemas (cont’d.)  Invalid state  Does not obey all the integrity constraints  Valid state  Satisfies all the constraints in the defined set of integrity constraints IC Basis Data Ganjil 2015/2016
  • 40. 40 Integrity, Referential Integrity, and Foreign Keys  Entity integrity constraint  No primary key value can be NULL  Referential integrity constraint  Specified between two relations  Maintains consistency among tuples in two relations Basis Data Ganjil 2015/2016
  • 41. 41 Integrity, Referential Integrity, and Foreign Keys (cont’d.) Basis Data Ganjil 2015/2016
  • 42. 42 Integrity, Referential Integrity, and Foreign Keys (cont’d.)  Foreign key rules:  The attributes in FK have the same domain(s) as the primary key attributes PK  Value of FK in a tuple t1 of the current state r1(R1) either occurs as a value of PK for some tuple t2 in the current state r2(R2) or is NULL Basis Data Ganjil 2015/2016
  • 43. 43 Integrity, Referential Integrity, and Foreign Keys (cont’d.)  Diagrammatically display referential integrity constraints  Directed arc from each foreign key to the relation it references  All integrity constraints should be specified on relational database schema Basis Data Ganjil 2015/2016
  • 44. 44 Other Types of Constraints  Semantic integrity constraints  May have to be specified and enforced on a relational database  Use triggers and assertions  More common to check for these types of constraints within the application programs Basis Data Ganjil 2015/2016
  • 45. 46 Latihan  Basis data yang memproses order (pemesanan) pada sebuah perusahaan memiliki 6 relasi berikut: CUSTOMER (Cust#, Cname, City) ORDER (Order#, Odate, Cust#, Ord_Amt) ORDER_ITEM (Order#, Item#, Qty) ITEM (Item#, Unit_price) SHIPMENT (Order#, Warehouse#, Ship_date) WAREHOUSE (Warehouse#, City) Ord_Amt mengacu pada jumlah harga pada satu kali order. Odate menyatakan tanggal pemesanan dilakukan, Ship_date menyatakan tanggal pengiriman barang yang dipesan customer dari gudang. Asumsikan bahwa suatu order dapat mengambil barang dari beberapa gudang (warehouse). Nyatakan foreign key yang mungkin untuk skema basis data ini. Basis Data Ganjil 2015/2016
  • 46. 47 Outline  The Relational Data Model  Characteristics of Relations  Relational Model Notation  Relational Model Constraints  Update Operations, Transactions, and Dealing with Constraint Violations Basis Data Ganjil 2015/2016
  • 47. 48 Update Operations, Transactions, and Dealing with Constraint Violations  Operations of the relational model can be categorized into retrievals and updates  Basic operations that change the states of relations in the database:  Insert  Delete  Update (or Modify) Basis Data Ganjil 2015/2016
  • 48. 49 Basis Data Ganjil 2015/2016
  • 49. 50 Basis Data Ganjil 2015/2016
  • 50. 51 The Insert Operation  Provides a list of attribute values for a new tuple t that is to be inserted into a relation R  Can violate any of the four types of constraints  If an insertion violates one or more constraints  Default option is to reject the insertion Basis Data Ganjil 2015/2016
  • 51. 52 The Delete Operation  Can violate only referential integrity  If tuple being deleted is referenced by foreign keys from other tuples  Restrict • Reject the deletion  Cascade • Propagate the deletion by deleting tuples that reference the tuple that is being deleted  Set null or set default • Modify the referencing attribute values that cause the violation Basis Data Ganjil 2015/2016
  • 52. 53 The Update Operation  Necessary to specify a condition on attributes of relation  Select the tuple (or tuples) to be modified  If attribute not part of a primary key nor of a foreign key  Usually causes no problems  Updating a primary/foreign key  Similar issues as with Insert/Delete Basis Data Ganjil 2015/2016
  • 53. 54 The Transaction Concept  Transaction  Executing program  Includes some database operations  Must leave the database in a valid or consistent state  Online transaction processing (OLTP) systems  Execute transactions at rates that reach several hundred per second Basis Data Ganjil 2015/2016
  • 54. 55 Latihan Basis Data Ganjil 2015/2016 Apakah ada constraints yang dilanggar pada operasi berikut? 1. Insert < 'ProductA', 4, 'Bellaire', 2 > into PROJECT. 2. Insert < '677678989', null, '40.0' > into WORKS_ON. 3. Delete the WORKS_ON tuples with ESSN= '333445555'. 4. Delete the EMPLOYEE tuple with SSN= '987654321'. 5. Modify the SUPERSSN attribute of the EMPLOYEE tuple with SSN= '999887777' to '943775543'.
  • 55. 56 Summary  Characteristics differentiate relations from ordinary tables or files  Classify database constraints into:  Inherent model-based constraints, explicit schema-based constraints, and application-based constraints  Modification operations on the relational model:  Insert, Delete, and Update Basis Data Ganjil 2015/2016