SlideShare a Scribd company logo
§  Constraints
§  Restrictions on the actual values in a database
state
§  Derived from the rules in the mini-world that the
database represents
§  Inherent model-based constraints or implicit
constraints
§  Inherent in the data model
30
Relational model constraints
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  Inherent model-based constraints or implicit
constraints
§  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
31
Relational model constraints
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
32
Domain constraints
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
33
Key constraints
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
34
Key constraints
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
35
Relational Databases and Relational Database schemas
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
36
Relational Databases and Relational Database schemas
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
37
Relational Databases and Relational Database schemas
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  Invalid state
§  Does not obey all the integrity constraints
§  Valid state
§  Satisfies all the constraints in the defined set of
integrity constraints IC
38
Relational Databases and Relational Database schemas
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  Entity integrity constraint
§  No primary key value can be NULL
§  Referential integrity constraint
§  Specified between two relations
§  Maintains consistency among tuples in two
relations
39
Integrity, Referential Integrity, and foreign keys
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
40
Integrity, Referential Integrity, and foreign keys
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
The conditions for a foreign key, given below, 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:
1.  The attributes in FK have the same domain(s) as the
primary key attributes PK of R2; the attributes FK are said
to reference or refer to the relation R2.
2.  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], and we say that the tuple t1 references or refers
to the tuple t2.
41
Integrity, Referential Integrity, and foreign keys
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
42
Integrity, Referential Integrity, and foreign keys
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
43
Integrity, Referential Integrity, and foreign keys
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  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
44
Other types of constraints
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  Functional dependency constraint
§  Establishes a functional relationship among two
sets of attributes X and Y
§  Value of X determines a unique value of Y
§  State constraints
§  Define the constraints that a valid state of the
database must satisfy
§  Transition constraints
§  Define to deal with state changes in the database
45
Other types of constraints
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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)
46
Update operations, Transactions, and dealing with
constraint violations
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
47
The insertion operation
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
48
The delete operation
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
49
The update operation
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  
§  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
50
The transaction concept
Fundamentals	
  of	
  Database	
  
Chapter	
  3:	
  The	
  rela7onal	
  data	
  model	
  and	
  the	
  
rela7onal	
  constraints	
  	
  	
  

More Related Content

PPTX
Uncertain Knowledge and Reasoning in Artificial Intelligence
PDF
CSC446: Pattern Recognition (LN5)
PDF
B.Tech.AIDS syllabus anna university .pdf
PPT
Monte Carlo Simulations
PDF
Gradient-based optimization for Deep Learning: a short introduction
PDF
NN_02_Threshold_Logic_Units.pdf
PPTX
Azure Digital Twins 2.0
PPTX
PROCEDURAL AND DECLARATIVE KNOWLEDGE IN AI & ML (1).pptx
Uncertain Knowledge and Reasoning in Artificial Intelligence
CSC446: Pattern Recognition (LN5)
B.Tech.AIDS syllabus anna university .pdf
Monte Carlo Simulations
Gradient-based optimization for Deep Learning: a short introduction
NN_02_Threshold_Logic_Units.pdf
Azure Digital Twins 2.0
PROCEDURAL AND DECLARATIVE KNOWLEDGE IN AI & ML (1).pptx

Viewers also liked (17)

PDF
Database Systems - Relational Data Model (Chapter 2)
PPTX
Database : Relational Data Model
PDF
4 the relational data model and relational database constraints
PDF
Apple - Compare iPad Models (2012/Oct')
DOC
Dbms Lecture Notes
PPTX
Chapter 6 relational data model and relational
PPTX
Datamodels & architecture
PDF
Chapter 2 Relational Data Model-part 3
PPTX
File and data base management
PDF
The Relational Data Model and Relational Database Constraints
PPTX
Relational Data Model Introduction
PDF
Chapter 2 Relational Data Model-part 2
PPT
Dbms ii mca-ch4-relational model-2013
PPTX
Database Normalization
PPT
3. Relational Models in DBMS
PDF
CBSE XII Database Concepts And MySQL Presentation
Database Systems - Relational Data Model (Chapter 2)
Database : Relational Data Model
4 the relational data model and relational database constraints
Apple - Compare iPad Models (2012/Oct')
Dbms Lecture Notes
Chapter 6 relational data model and relational
Datamodels & architecture
Chapter 2 Relational Data Model-part 3
File and data base management
The Relational Data Model and Relational Database Constraints
Relational Data Model Introduction
Chapter 2 Relational Data Model-part 2
Dbms ii mca-ch4-relational model-2013
Database Normalization
3. Relational Models in DBMS
CBSE XII Database Concepts And MySQL Presentation
Ad

Similar to Chapter3 the relational data model and the relation database constraints part2 (20)

PPTX
Fundamentals of database system - Relational data model and relational datab...
PDF
4_RelationalDataModelAndRelationalMapping.pdf
PPTX
The relational data model part[1]
PDF
Chapter 2 Database System Architecture.pdf
PPT
Database Technology Teaching Material For Learn
PPTX
Relational Model and Relational Algebra.pptx
PDF
Relational Model on Database management PPT
PPTX
Chapter 6 relational data model and relational
PPT
Lecture 07 relational database management system
PPTX
Chapter 6 relational data model and relational
PDF
unit-3_Chapter1_RDRA.pdf
PPTX
Module 2 2022 scheme BCS403 database management system
PPTX
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_2.pptx
PPTX
Dbms relational data model and sql queries
PDF
2. Chapter Two.pdf
PPT
Chapter 5: Database superclass, subclass
PPTX
Relational model
PPT
ENCh05.ppt
PPTX
Database.pptx
PDF
Dbms 9: Relational Model
Fundamentals of database system - Relational data model and relational datab...
4_RelationalDataModelAndRelationalMapping.pdf
The relational data model part[1]
Chapter 2 Database System Architecture.pdf
Database Technology Teaching Material For Learn
Relational Model and Relational Algebra.pptx
Relational Model on Database management PPT
Chapter 6 relational data model and relational
Lecture 07 relational database management system
Chapter 6 relational data model and relational
unit-3_Chapter1_RDRA.pdf
Module 2 2022 scheme BCS403 database management system
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_2.pptx
Dbms relational data model and sql queries
2. Chapter Two.pdf
Chapter 5: Database superclass, subclass
Relational model
ENCh05.ppt
Database.pptx
Dbms 9: Relational Model
Ad

Recently uploaded (20)

PPTX
slide head and neck muscel for medical students
PDF
Tracing_medieval_maces_of_Romania_Evalua (2).pdf
PPTX
Certificados y Diplomas para Educación de Colores Candy by Slidesgo.pptx
PPT
capnography & pulse oxymeuuuuuuutry (1).ppt
PPTX
Rebel and Raj_ Revolt of 1857 and representation.pptx
PPTX
vsfbvefbegbefvsegbthnmthndgbdfvbrsjmrysnedgbdzndhzmsr
PPTX
LESSON 3.ANG HEOGRAPIYANG PANTAO NG TIMOG SILANGANG ASYA.pptx
PPTX
20068987-achievement power templates.pptx
PPTX
UCSP MOD 2 PPT hajdkfouvkhfkdsdyfychkyhfdi
PPTX
The diary of a young girl (1).pptx ANNE Frank
PPTX
Technical-Codes-presentation-G-12Student
PPTX
estudiovalentinesartemodernoparaocasionesespecialesyfechas.pptx
PPSX
Multiple scenes in a single painting.ppsx
PPTX
Lesson 1-Principles of Indigenous Creative Crafts.pptx
DOCX
PLAN OF ACTIVITIES AND PROGRAM FOR ALL STUDENTSS
PPTX
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
; Projeto Rixa Antiga.pdf
PDF
CSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
PDF
Close Enough S3 E7 "Bridgette the Brain"
PPTX
Callie Slide Show Slide Show Slide Show S
slide head and neck muscel for medical students
Tracing_medieval_maces_of_Romania_Evalua (2).pdf
Certificados y Diplomas para Educación de Colores Candy by Slidesgo.pptx
capnography & pulse oxymeuuuuuuutry (1).ppt
Rebel and Raj_ Revolt of 1857 and representation.pptx
vsfbvefbegbefvsegbthnmthndgbdfvbrsjmrysnedgbdzndhzmsr
LESSON 3.ANG HEOGRAPIYANG PANTAO NG TIMOG SILANGANG ASYA.pptx
20068987-achievement power templates.pptx
UCSP MOD 2 PPT hajdkfouvkhfkdsdyfychkyhfdi
The diary of a young girl (1).pptx ANNE Frank
Technical-Codes-presentation-G-12Student
estudiovalentinesartemodernoparaocasionesespecialesyfechas.pptx
Multiple scenes in a single painting.ppsx
Lesson 1-Principles of Indigenous Creative Crafts.pptx
PLAN OF ACTIVITIES AND PROGRAM FOR ALL STUDENTSS
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
; Projeto Rixa Antiga.pdf
CSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
Close Enough S3 E7 "Bridgette the Brain"
Callie Slide Show Slide Show Slide Show S

Chapter3 the relational data model and the relation database constraints part2

  • 1. §  Constraints §  Restrictions on the actual values in a database state §  Derived from the rules in the mini-world that the database represents §  Inherent model-based constraints or implicit constraints §  Inherent in the data model 30 Relational model constraints Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 2. §  Inherent model-based constraints or implicit constraints §  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 31 Relational model constraints Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 3. §  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 32 Domain constraints Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 4. §  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 33 Key constraints Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 5. 34 Key constraints Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 6. §  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 35 Relational Databases and Relational Database schemas Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 7. 36 Relational Databases and Relational Database schemas Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 8. 37 Relational Databases and Relational Database schemas Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 9. §  Invalid state §  Does not obey all the integrity constraints §  Valid state §  Satisfies all the constraints in the defined set of integrity constraints IC 38 Relational Databases and Relational Database schemas Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 10. §  Entity integrity constraint §  No primary key value can be NULL §  Referential integrity constraint §  Specified between two relations §  Maintains consistency among tuples in two relations 39 Integrity, Referential Integrity, and foreign keys Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 11. §  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 40 Integrity, Referential Integrity, and foreign keys Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 12. The conditions for a foreign key, given below, 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: 1.  The attributes in FK have the same domain(s) as the primary key attributes PK of R2; the attributes FK are said to reference or refer to the relation R2. 2.  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], and we say that the tuple t1 references or refers to the tuple t2. 41 Integrity, Referential Integrity, and foreign keys Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 13. §  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 42 Integrity, Referential Integrity, and foreign keys Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 14. 43 Integrity, Referential Integrity, and foreign keys Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 15. §  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 44 Other types of constraints Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 16. §  Functional dependency constraint §  Establishes a functional relationship among two sets of attributes X and Y §  Value of X determines a unique value of Y §  State constraints §  Define the constraints that a valid state of the database must satisfy §  Transition constraints §  Define to deal with state changes in the database 45 Other types of constraints Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 17. §  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) 46 Update operations, Transactions, and dealing with constraint violations Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 18. §  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 47 The insertion operation Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 19. §  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 48 The delete operation Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 20. §  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 49 The update operation Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints      
  • 21. §  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 50 The transaction concept Fundamentals  of  Database   Chapter  3:  The  rela7onal  data  model  and  the   rela7onal  constraints