SlideShare una empresa de Scribd logo
1 de 28
Fundamentals of Database systems
Ministry of Higher Education
Bamyan University
Computer Science Department
1
Presented by : Mustafa Kamel Mohammadi
Email : bamian.cs@gmail.com
Relational data model and relational database constraints
Fundamentals of database system 6th edition
Learning objective
 In his chapter you will learn
 Relational data model concepts
 Relational data model constraints
 Characteristics of relation
2
Relational Model Concepts
The Relational model represents the database as a collection of relations.
Each relation resembles a table of values
Each row in the table represents a collection of related data values. A row
represents a
 Real-world entity
 Relationship
Table name and column names are used to help to interpret the meaning of the
values in each row.
In the formal relational model terminology
 A row is called a tuple
 A column header is called an attribute
 The table is called a relation
 The data type describing the types of values that can appear in each column is represented
by a domain of possible values
3
Cont.
Domain
A domain D is a set of atomic values.
By atomic we mean that each value in the domain is indivisible
Method of specifying a domain is to specify a data type
 Usa_phone_numbers. The set of ten-digit phone numbers valid in the United States.
 Social_security_numbers. The set of valid nine-digit Social Security numbers.
 (This is a unique identifier assigned to each person in the United States for employment, tax, and
benefits purposes.)
 Names. The set of character strings that represent names of persons.
The preceding are called logical definitions of domains.
A domain is thus given a name, data type, and format
 ISBN = xxx-xxxx-xxxx-xxxx , x can contain (0-9, A-Z)
4
Cont.
Relation schema
A relation schema R, denoted by R(A1, A2, ...,An) is made up of a relation name R
and a list of attributes, A1, A2, ..., An
Each attribute Ai is identified by dom (Ai)
The degree of a relation is the number of attributes of its relation schema
A relation of degree seven
 STUDENT(Name, Ssn, Home_phone, Address, Office_phone, Age, Gpa)
Using the data type of each attribute, the definition is sometimes written as:
 STUDENT(Name: string, Ssn: string, Home_phone: string, Address: string,Office_phone:
string, Age: integer, Gpa: real)
Attribute A can be qualified with the relation name R to which it belongs by using
the dot notation R.A , for example, STUDENT.name
5
Cont.
Relation state
Denoted by r(R), is a set of n-tuples r = {t1, t2, ..., tn}.
Denoted by lower case letter (r)
Each tuple (t) is an 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
It is possible for several attributes to have the same domain. The attribute names
indicate different roles
 USA_phone_numbers plays the role of Home_phone
 USA_phone_numbers plays the role of office_phone
6
7
Characteristics of Relations
Ordering of Tuples in a Relation
 Logically because relation is defined as a set of tuples. Mathematically, elements of a set
have no order among them.
 Physically there always is an order among the records. This ordering indicates first,
second, ith, and last records in the file
 When we display a relation as a table, the rows are displayed in a certain order by
different attributes.
Values and NULLs in the Tuples
 Each value in a tuple is an atomic value
 Composite and multivalued attributes are not allowed
 Null is used to represent values that are
 value unknown
 value exists but is not available
 Attribute does not apply
8
Cont.
Interpretation (Meaning) of a Relation
The relation schema can be interpreted as a declaration.
Each tuple in the relation can then be interpreted as a fact or a particular
instance of the assertion
 Some relations may represent facts about entities
 Whereas other relations may represent facts about relationships.
9
Relational Model Constraints
There are generally many restrictions or constraints on the actual values in a
database state
Constraints on databases can generally be divided into three main categories:
 Constraints that are inherent in the data model. We call these inherent model-based
constraints or implicit constraints
 Constraints that can be directly expressed in schemas of the data model, typically by
specifying them in the DDL ,We call these schema-based constraints or explicit constraints.
 Constraints that cannot be directly expressed in the schemas of the data model, and hence
must be enforced by the application programs. We call these application-based or semantic
constraints or business rules.
10
Explicit or Schema Based constraints
Domain constraints
Specify that within each tuple, the value of each attribute A must be an atomic
value.
Key Constraints
Means that no two tuples can have the same combination of values for all their
attributes.
Subsets of attributes of a relation schema R with the property that no two tuples
in any relation state r of R is called a super key.
A super key can have redundant attributes so removing those attributes makes
the concept of key.
 Key is a minimal super key that is, a super key from which we cannot remove any attributes
and still have the uniqueness constraint
11
12
Cont.
 A key is also a super key but not vice versa
 Example: {Ssn, Name, Age} is a super key for R (STUDENT) but not a key, because removing Name
and Age still leaves us with a super key.
 The value of a key attribute can be used to identify uniquely each tuple in the relation.
 A relation schema may have more than one key. In this case, each of the keys is called a candidate
key
 For example, the CAR relation in Figure 3.4 has two candidate keys: License_number and
Engine_serial_number
 Primary key of the relation is the candidate key whose values are used to identify tuples in the
relation. Primary keys are underlined in schema diagram.
 The choice of one to become the primary key is arbitrary.
 The other candidate keys are designated as unique keys.
13
Cont.
Null value constraints
Another constraint on attributes specifies whether NULL values are or are not
permitted.
NULL
 Can have or have not value
NOT NULL
 Must have value, it can not be empty
14
Relational Databases and Relational Database Schema
A relational database usually contains many relations, with tuples in relations that
are related in various ways.
A relational database schema S is a set of relation schemas S = {R1, R2, ..., Rm }.
A relational database state DB of relational schema S is a set of relation states DB
= {r1, r2, ..., rm} such that each ri is a state of Ri
Example:
 COMPANY = {EMPLOYEE, DEPARTMENT,DEPT_LOCATIONS, PROJECT, WORKS_ON,
DEPENDENT}
When we refer to a relational database, we implicitly include both its schema and
its current state.
15
Cont.
Attributes that represent different concepts may have the same name in different
relations
For example
 we could have used the attribute name Name for both PROJECT and DEPARTMENT.
The same real-world concept is used in different roles (meanings) in the same
relation
 Ssn and super_ssn …. Must have different names
16
17
Relational Schema Diagram
18
Relational Database State
Integrity constraint
Integrity constraint states that no primary key value can be NULL
 because the primary key value is used to identify individual tuples in a relation. Having NULL
values for the primary key implies that we cannot identify some tuples
Key constraints and entity integrity constraints are specified on individual
relations.
Referential integrity constraint is specified between two relations and is used to
maintain the consistency and relationship among tuples in the two relations.
the referential integrity constraint states that a tuple in one relation that refers to
another relation must refer to an existing tuple in that relation
 Dno of EMPLOYEE gives the department number for which each employee works,hence, its
value in every EMPLOYEE tuple must match the Dnumber value of some tuple in the
DEPARTMENT relation
Referential integrity constraint is maintained by foreign keys.
19
20
Referential integrity constraints
Foreign key
Specify a referential integrity constraint between the two relation schemas R1
and R2.
A set of attributes FK in relation schema R1 is a foreign key of R1 that references
relation R2 if it satisfies the following rules.
 The attributes in FK have the same domain(s) as the primary key attributes PK of R2.
 A 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. In the former case, we have t1[FK] = t2[PK]
R1 is called the referencing relation and R2 is the referenced relation.
A foreign key could have NULL values
 when doesn’t related to other relation
 when it is not being used as primary key
a foreign key can refer to its own relation
21
Other types of constraints
Semantic integrity constraints
 the salary of an employee should not exceed the salary of the employee’s supervisor
 maximum number of hours an employee can work on all projects per week is 56.
 specified and enforced within the application programs that update the database
General-purpose constraint specification language.
 Use Mechanisms called triggers and assertions
22
Operations and Constraint violation
The operations of the relational model can be categorized into retrievals and
updates
 retrievals operations
 database modification or update operations
three basic operations that can change the states of relations in the database:
Insert, Delete, and Update
Whenever these operations are applied, the integrity constraints specified on the
relational database schema should not be violated
23
Insert operation
The Insert operation provides a list of attribute values for a new tuple t that is to
be inserted into a relation R
insert can violate any of the four types of constraints discussed
 Domain constraints can be violated if an attribute value is given that does not appear in the
corresponding domain
 Key constraints can be violated if a key value in the new tuple t already exists in another tuple
in the relation r(R)
 Entity integrity can be violated if any part of the primary key of the new tuple t is NULL
 Referential integrity can be violated if the value of any foreign key in t refers to a tuple that
does not exist in the referenced relation
If an insertion violates one or more constraints, the default option is to reject the
insertion
24
Delete operation
The Delete operation can violate only referential integrity.
This occurs if the tuple being deleted is referenced by foreign keys from other
tuples in the database.
Several options are available if a deletion operation causes a violation
 restrict rejects the deletion
 Cascade attempts to cascade (or propagate) the deletion by deleting tuples that reference
the tuple that is being deleted
 set null
 set default
25
The Update operation
 The Update (or Modify) operation is used to change the values of one or more attributes in a
tuple (or tuples) of some relation R.
 Updating an attribute that is neither part of a primary key nor of a foreign key usually causes no
problems.
 check to confirm that the new value is of the correct data type and domain
 Modifying a primary key value is similar to deleting one tuple and inserting another in its place
 If a foreign key attribute is modified, the DBMS must make sure that the new value refers to an
existing tuple in the referenced relation
26
The Transaction Concept
A database application program running against a relational database typically
executes one or more transactions
A transaction is an executing program that includes some database operations,
such as
 reading from the database
 applying insertions, deletions, or updates to the database.
At the end of the transaction, it must leave the database in a valid or consistent
state that satisfies all the constraints specified on the database schema
27
28

Más contenido relacionado

La actualidad más candente

Relational algebra in DBMS
Relational algebra in DBMSRelational algebra in DBMS
Relational algebra in DBMSArafat Hossan
 
Database Keys & Relationship
Database Keys & RelationshipDatabase Keys & Relationship
Database Keys & RelationshipBellal Hossain
 
Database System Concepts and Architecture
Database System Concepts and ArchitectureDatabase System Concepts and Architecture
Database System Concepts and Architecturesontumax
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to databasePradnya Saval
 
Database Design and the ER Model, Indexing and Hashing
Database Design and the ER Model, Indexing and HashingDatabase Design and the ER Model, Indexing and Hashing
Database Design and the ER Model, Indexing and HashingPrabu U
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancyVisakh V
 
Normalization of Data Base
Normalization of Data BaseNormalization of Data Base
Normalization of Data BaseRavinder Kamboj
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Oum Saokosal
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraintsKumar
 
Ppt of dbms e r features
Ppt of dbms e r featuresPpt of dbms e r features
Ppt of dbms e r featuresNirali Akabari
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model IntroductionNishant Munjal
 
Types of Database Models
Types of Database ModelsTypes of Database Models
Types of Database ModelsMurassa Gillani
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Jargalsaikhan Alyeksandr
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbmsmaryeem
 
1 introduction databases and database users
1 introduction databases and database users1 introduction databases and database users
1 introduction databases and database usersKumar
 
Enhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) ModelingEnhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) Modelingsontumax
 

La actualidad más candente (20)

Relational algebra in DBMS
Relational algebra in DBMSRelational algebra in DBMS
Relational algebra in DBMS
 
Database Keys & Relationship
Database Keys & RelationshipDatabase Keys & Relationship
Database Keys & Relationship
 
Database System Concepts and Architecture
Database System Concepts and ArchitectureDatabase System Concepts and Architecture
Database System Concepts and Architecture
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Databases: Normalisation
Databases: NormalisationDatabases: Normalisation
Databases: Normalisation
 
The Relational Model
The Relational ModelThe Relational Model
The Relational Model
 
Types of keys dbms
Types of keys dbmsTypes of keys dbms
Types of keys dbms
 
Database Design and the ER Model, Indexing and Hashing
Database Design and the ER Model, Indexing and HashingDatabase Design and the ER Model, Indexing and Hashing
Database Design and the ER Model, Indexing and Hashing
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancy
 
Normalization of Data Base
Normalization of Data BaseNormalization of Data Base
Normalization of Data Base
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraints
 
Ppt of dbms e r features
Ppt of dbms e r featuresPpt of dbms e r features
Ppt of dbms e r features
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Types of Database Models
Types of Database ModelsTypes of Database Models
Types of Database Models
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
 
1 introduction databases and database users
1 introduction databases and database users1 introduction databases and database users
1 introduction databases and database users
 
Enhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) ModelingEnhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) Modeling
 

Destacado

Urinary system embryology
Urinary system embryologyUrinary system embryology
Urinary system embryologyishtiaqqazi
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraintsNikhil Deswal
 
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
 
Introduction to RDBMS
Introduction to RDBMSIntroduction to RDBMS
Introduction to RDBMSSarmad Ali
 
Relational database management system (rdbms) i
Relational database management system (rdbms) iRelational database management system (rdbms) i
Relational database management system (rdbms) iRavinder Kamboj
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallJohn Mulhall
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMSkoolkampus
 
14. Query Optimization in DBMS
14. Query Optimization in DBMS14. Query Optimization in DBMS
14. Query Optimization in DBMSkoolkampus
 
Rdbms
RdbmsRdbms
Rdbmsrdbms
 

Destacado (12)

Urinary system embryology
Urinary system embryologyUrinary system embryology
Urinary system embryology
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
 
The relational data model part[1]
The relational data model part[1]The relational data model part[1]
The relational data model part[1]
 
Introduction to RDBMS
Introduction to RDBMSIntroduction to RDBMS
Introduction to RDBMS
 
Rdbms
RdbmsRdbms
Rdbms
 
Relational database management system (rdbms) i
Relational database management system (rdbms) iRelational database management system (rdbms) i
Relational database management system (rdbms) i
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
 
Denormalization
DenormalizationDenormalization
Denormalization
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
 
RDBMS.ppt
RDBMS.pptRDBMS.ppt
RDBMS.ppt
 
14. Query Optimization in DBMS
14. Query Optimization in DBMS14. Query Optimization in DBMS
14. Query Optimization in DBMS
 
Rdbms
RdbmsRdbms
Rdbms
 

Similar a Fundamentals of database system - Relational data model and relational database constraints

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
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdfLPhct2
 
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
 
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-2013Prosanta Ghosh
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptxThangamaniR3
 
ER Model and other topics in DBMS
ER Model and other topics in DBMSER Model and other topics in DBMS
ER Model and other topics in DBMSHarinarayananR2
 
Dbms Concepts
Dbms ConceptsDbms Concepts
Dbms Conceptsadukkas
 
Dbms presentation
Dbms presentationDbms presentation
Dbms presentationamaresh144
 
2. relational model_150903
2. relational model_1509032. relational model_150903
2. relational model_150903Dika Handika
 
Lecture 07 relational database management system
Lecture 07 relational database management systemLecture 07 relational database management system
Lecture 07 relational database management systememailharmeet
 

Similar a Fundamentals of database system - Relational data model and relational database constraints (20)

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
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
 
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...
 
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
 
DBMS Unit-2.pdf
DBMS Unit-2.pdfDBMS Unit-2.pdf
DBMS Unit-2.pdf
 
Relational Model
Relational ModelRelational Model
Relational Model
 
Unit 3 final.pptx
Unit 3 final.pptxUnit 3 final.pptx
Unit 3 final.pptx
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptx
 
unit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdfunit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdf
 
Unit-2.pdf
Unit-2.pdfUnit-2.pdf
Unit-2.pdf
 
ER Model and other topics in DBMS
ER Model and other topics in DBMSER Model and other topics in DBMS
ER Model and other topics in DBMS
 
L7 er2
L7 er2L7 er2
L7 er2
 
NMEC RD_UNIT 1.ppt
NMEC RD_UNIT 1.pptNMEC RD_UNIT 1.ppt
NMEC RD_UNIT 1.ppt
 
Dbms Concepts
Dbms ConceptsDbms Concepts
Dbms Concepts
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
DBMS-Unit-2.pptx
DBMS-Unit-2.pptxDBMS-Unit-2.pptx
DBMS-Unit-2.pptx
 
Dbms presentation
Dbms presentationDbms presentation
Dbms presentation
 
2. relational model_150903
2. relational model_1509032. relational model_150903
2. relational model_150903
 
Lecture 07 relational database management system
Lecture 07 relational database management systemLecture 07 relational database management system
Lecture 07 relational database management system
 

Más de Mustafa Kamel Mohammadi

Web design - Working with tables in HTML
Web design - Working with tables in HTMLWeb design - Working with tables in HTML
Web design - Working with tables in HTMLMustafa Kamel Mohammadi
 
Web design - Working with Links and Images
Web design - Working with Links and ImagesWeb design - Working with Links and Images
Web design - Working with Links and ImagesMustafa Kamel Mohammadi
 
Web design - Working with Text and Lists in HTML
Web design - Working with Text and Lists in HTMLWeb design - Working with Text and Lists in HTML
Web design - Working with Text and Lists in HTMLMustafa Kamel Mohammadi
 
Web design - HTML (Hypertext Markup Language) introduction
Web design - HTML (Hypertext Markup Language) introductionWeb design - HTML (Hypertext Markup Language) introduction
Web design - HTML (Hypertext Markup Language) introductionMustafa Kamel Mohammadi
 
Web design - Applications and web application definition
Web design - Applications and web application definitionWeb design - Applications and web application definition
Web design - Applications and web application definitionMustafa Kamel Mohammadi
 
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...Mustafa Kamel Mohammadi
 
Fundamentals of database system - Database System Concepts and Architecture
Fundamentals of database system - Database System Concepts and ArchitectureFundamentals of database system - Database System Concepts and Architecture
Fundamentals of database system - Database System Concepts and ArchitectureMustafa Kamel Mohammadi
 
Fundamentals of Database system - Databases and Database Users
Fundamentals of Database system - Databases and Database UsersFundamentals of Database system - Databases and Database Users
Fundamentals of Database system - Databases and Database UsersMustafa Kamel Mohammadi
 

Más de Mustafa Kamel Mohammadi (10)

Web design - Working with forms in HTML
Web design - Working with forms in HTMLWeb design - Working with forms in HTML
Web design - Working with forms in HTML
 
Web design - Working with tables in HTML
Web design - Working with tables in HTMLWeb design - Working with tables in HTML
Web design - Working with tables in HTML
 
Web design - Working with Links and Images
Web design - Working with Links and ImagesWeb design - Working with Links and Images
Web design - Working with Links and Images
 
Web design - Working with Text and Lists in HTML
Web design - Working with Text and Lists in HTMLWeb design - Working with Text and Lists in HTML
Web design - Working with Text and Lists in HTML
 
Web design - HTML (Hypertext Markup Language) introduction
Web design - HTML (Hypertext Markup Language) introductionWeb design - HTML (Hypertext Markup Language) introduction
Web design - HTML (Hypertext Markup Language) introduction
 
Web design - How the Web works?
Web design - How the Web works?Web design - How the Web works?
Web design - How the Web works?
 
Web design - Applications and web application definition
Web design - Applications and web application definitionWeb design - Applications and web application definition
Web design - Applications and web application definition
 
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
 
Fundamentals of database system - Database System Concepts and Architecture
Fundamentals of database system - Database System Concepts and ArchitectureFundamentals of database system - Database System Concepts and Architecture
Fundamentals of database system - Database System Concepts and Architecture
 
Fundamentals of Database system - Databases and Database Users
Fundamentals of Database system - Databases and Database UsersFundamentals of Database system - Databases and Database Users
Fundamentals of Database system - Databases and Database Users
 

Último

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Fundamentals of database system - Relational data model and relational database constraints

  • 1. Fundamentals of Database systems Ministry of Higher Education Bamyan University Computer Science Department 1 Presented by : Mustafa Kamel Mohammadi Email : bamian.cs@gmail.com Relational data model and relational database constraints Fundamentals of database system 6th edition
  • 2. Learning objective  In his chapter you will learn  Relational data model concepts  Relational data model constraints  Characteristics of relation 2
  • 3. Relational Model Concepts The Relational model represents the database as a collection of relations. Each relation resembles a table of values Each row in the table represents a collection of related data values. A row represents a  Real-world entity  Relationship Table name and column names are used to help to interpret the meaning of the values in each row. In the formal relational model terminology  A row is called a tuple  A column header is called an attribute  The table is called a relation  The data type describing the types of values that can appear in each column is represented by a domain of possible values 3
  • 4. Cont. Domain A domain D is a set of atomic values. By atomic we mean that each value in the domain is indivisible Method of specifying a domain is to specify a data type  Usa_phone_numbers. The set of ten-digit phone numbers valid in the United States.  Social_security_numbers. The set of valid nine-digit Social Security numbers.  (This is a unique identifier assigned to each person in the United States for employment, tax, and benefits purposes.)  Names. The set of character strings that represent names of persons. The preceding are called logical definitions of domains. A domain is thus given a name, data type, and format  ISBN = xxx-xxxx-xxxx-xxxx , x can contain (0-9, A-Z) 4
  • 5. Cont. Relation schema A relation schema R, denoted by R(A1, A2, ...,An) is made up of a relation name R and a list of attributes, A1, A2, ..., An Each attribute Ai is identified by dom (Ai) The degree of a relation is the number of attributes of its relation schema A relation of degree seven  STUDENT(Name, Ssn, Home_phone, Address, Office_phone, Age, Gpa) Using the data type of each attribute, the definition is sometimes written as:  STUDENT(Name: string, Ssn: string, Home_phone: string, Address: string,Office_phone: string, Age: integer, Gpa: real) Attribute A can be qualified with the relation name R to which it belongs by using the dot notation R.A , for example, STUDENT.name 5
  • 6. Cont. Relation state Denoted by r(R), is a set of n-tuples r = {t1, t2, ..., tn}. Denoted by lower case letter (r) Each tuple (t) is an 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 It is possible for several attributes to have the same domain. The attribute names indicate different roles  USA_phone_numbers plays the role of Home_phone  USA_phone_numbers plays the role of office_phone 6
  • 7. 7
  • 8. Characteristics of Relations Ordering of Tuples in a Relation  Logically because relation is defined as a set of tuples. Mathematically, elements of a set have no order among them.  Physically there always is an order among the records. This ordering indicates first, second, ith, and last records in the file  When we display a relation as a table, the rows are displayed in a certain order by different attributes. Values and NULLs in the Tuples  Each value in a tuple is an atomic value  Composite and multivalued attributes are not allowed  Null is used to represent values that are  value unknown  value exists but is not available  Attribute does not apply 8
  • 9. Cont. Interpretation (Meaning) of a Relation The relation schema can be interpreted as a declaration. Each tuple in the relation can then be interpreted as a fact or a particular instance of the assertion  Some relations may represent facts about entities  Whereas other relations may represent facts about relationships. 9
  • 10. Relational Model Constraints There are generally many restrictions or constraints on the actual values in a database state Constraints on databases can generally be divided into three main categories:  Constraints that are inherent in the data model. We call these inherent model-based constraints or implicit constraints  Constraints that can be directly expressed in schemas of the data model, typically by specifying them in the DDL ,We call these schema-based constraints or explicit constraints.  Constraints that cannot be directly expressed in the schemas of the data model, and hence must be enforced by the application programs. We call these application-based or semantic constraints or business rules. 10
  • 11. Explicit or Schema Based constraints Domain constraints Specify that within each tuple, the value of each attribute A must be an atomic value. Key Constraints Means that no two tuples can have the same combination of values for all their attributes. Subsets of attributes of a relation schema R with the property that no two tuples in any relation state r of R is called a super key. A super key can have redundant attributes so removing those attributes makes the concept of key.  Key is a minimal super key that is, a super key from which we cannot remove any attributes and still have the uniqueness constraint 11
  • 12. 12
  • 13. Cont.  A key is also a super key but not vice versa  Example: {Ssn, Name, Age} is a super key for R (STUDENT) but not a key, because removing Name and Age still leaves us with a super key.  The value of a key attribute can be used to identify uniquely each tuple in the relation.  A relation schema may have more than one key. In this case, each of the keys is called a candidate key  For example, the CAR relation in Figure 3.4 has two candidate keys: License_number and Engine_serial_number  Primary key of the relation is the candidate key whose values are used to identify tuples in the relation. Primary keys are underlined in schema diagram.  The choice of one to become the primary key is arbitrary.  The other candidate keys are designated as unique keys. 13
  • 14. Cont. Null value constraints Another constraint on attributes specifies whether NULL values are or are not permitted. NULL  Can have or have not value NOT NULL  Must have value, it can not be empty 14
  • 15. Relational Databases and Relational Database Schema A relational database usually contains many relations, with tuples in relations that are related in various ways. A relational database schema S is a set of relation schemas S = {R1, R2, ..., Rm }. A relational database state DB of relational schema S is a set of relation states DB = {r1, r2, ..., rm} such that each ri is a state of Ri Example:  COMPANY = {EMPLOYEE, DEPARTMENT,DEPT_LOCATIONS, PROJECT, WORKS_ON, DEPENDENT} When we refer to a relational database, we implicitly include both its schema and its current state. 15
  • 16. Cont. Attributes that represent different concepts may have the same name in different relations For example  we could have used the attribute name Name for both PROJECT and DEPARTMENT. The same real-world concept is used in different roles (meanings) in the same relation  Ssn and super_ssn …. Must have different names 16
  • 19. Integrity constraint Integrity constraint states that no primary key value can be NULL  because the primary key value is used to identify individual tuples in a relation. Having NULL values for the primary key implies that we cannot identify some tuples Key constraints and entity integrity constraints are specified on individual relations. Referential integrity constraint is specified between two relations and is used to maintain the consistency and relationship among tuples in the two relations. the referential integrity constraint states that a tuple in one relation that refers to another relation must refer to an existing tuple in that relation  Dno of EMPLOYEE gives the department number for which each employee works,hence, its value in every EMPLOYEE tuple must match the Dnumber value of some tuple in the DEPARTMENT relation Referential integrity constraint is maintained by foreign keys. 19
  • 21. Foreign key Specify a referential integrity constraint between the two relation schemas R1 and R2. A set of attributes FK in relation schema R1 is a foreign key of R1 that references relation R2 if it satisfies the following rules.  The attributes in FK have the same domain(s) as the primary key attributes PK of R2.  A 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. In the former case, we have t1[FK] = t2[PK] R1 is called the referencing relation and R2 is the referenced relation. A foreign key could have NULL values  when doesn’t related to other relation  when it is not being used as primary key a foreign key can refer to its own relation 21
  • 22. Other types of constraints Semantic integrity constraints  the salary of an employee should not exceed the salary of the employee’s supervisor  maximum number of hours an employee can work on all projects per week is 56.  specified and enforced within the application programs that update the database General-purpose constraint specification language.  Use Mechanisms called triggers and assertions 22
  • 23. Operations and Constraint violation The operations of the relational model can be categorized into retrievals and updates  retrievals operations  database modification or update operations three basic operations that can change the states of relations in the database: Insert, Delete, and Update Whenever these operations are applied, the integrity constraints specified on the relational database schema should not be violated 23
  • 24. Insert operation The Insert operation provides a list of attribute values for a new tuple t that is to be inserted into a relation R insert can violate any of the four types of constraints discussed  Domain constraints can be violated if an attribute value is given that does not appear in the corresponding domain  Key constraints can be violated if a key value in the new tuple t already exists in another tuple in the relation r(R)  Entity integrity can be violated if any part of the primary key of the new tuple t is NULL  Referential integrity can be violated if the value of any foreign key in t refers to a tuple that does not exist in the referenced relation If an insertion violates one or more constraints, the default option is to reject the insertion 24
  • 25. Delete operation The Delete operation can violate only referential integrity. This occurs if the tuple being deleted is referenced by foreign keys from other tuples in the database. Several options are available if a deletion operation causes a violation  restrict rejects the deletion  Cascade attempts to cascade (or propagate) the deletion by deleting tuples that reference the tuple that is being deleted  set null  set default 25
  • 26. The Update operation  The Update (or Modify) operation is used to change the values of one or more attributes in a tuple (or tuples) of some relation R.  Updating an attribute that is neither part of a primary key nor of a foreign key usually causes no problems.  check to confirm that the new value is of the correct data type and domain  Modifying a primary key value is similar to deleting one tuple and inserting another in its place  If a foreign key attribute is modified, the DBMS must make sure that the new value refers to an existing tuple in the referenced relation 26
  • 27. The Transaction Concept A database application program running against a relational database typically executes one or more transactions A transaction is an executing program that includes some database operations, such as  reading from the database  applying insertions, deletions, or updates to the database. At the end of the transaction, it must leave the database in a valid or consistent state that satisfies all the constraints specified on the database schema 27
  • 28. 28