0% found this document useful (0 votes)
178 views23 pages

DBMS Constraints

The relational Model of Data is based on the concept of A Relation. Each relation resembles a table of values each row in the table represents a collection of related data values. A Relation may be regarded as a set of tuples (rows) a column in a table are also called attributes of the relation.

Uploaded by

kanz_85
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views23 pages

DBMS Constraints

The relational Model of Data is based on the concept of A Relation. Each relation resembles a table of values each row in the table represents a collection of related data values. A Relation may be regarded as a set of tuples (rows) a column in a table are also called attributes of the relation.

Uploaded by

kanz_85
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Chapter 5

The Relational Data Model and Relational Database Constraints

Copyright 2004 Pearson Education, Inc.

Chapter Outline
Relational Model Concepts Relational Model Constraints and Relational

Database Schemas Update Operations and Dealing with Constraint Violations

Chapter 5-3

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Relational Model Concepts


The relational Model of Data is based on the

concept of a Relation. Each relation resembles a table of values Each row in the table represents a collection of related data values Each row in the table represents a fact tht typically corresponds to a real world entity or relationship A Row is called a tuple A column header is called a attribute Table is called a relation A Relation is a mathematical concept based on the ideas of sets.
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Chapter 5-4

FORMAL DEFINITIONS
The Schema of a Relation: R (A1, A2, .....An), is made

up of relation name R and list of attributes A1, A2..An Relation schema R is defined over attributes A1, A2, .....An For Example CUSTOMER (Cust-id, Cust-name, Address, Phone#) **Above example is a relation of degree 4

Here, CUSTOMER is a relation defined over the four attributes Cust-id, Cust-name, Address, Phone#, each of which has a domain or a set of valid values. For example, the domain of Cust-id is 6 digit numbers.

Chapter 5-5

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

FORMAL DEFINITIONS
A tuple is an ordered set of values Each value is derived from an appropriate domain. Each row in the CUSTOMER table may be referred to

as a tuple in the table and would consist of four values.

<632895, "John Smith", "101 Main St. Atlanta, GA 30332", "(404) 894-2000">

is a tuple belonging to the CUSTOMER relation. A relation may be regarded as a set of tuples (rows). Columns in a table are also called attributes of the relation.

Chapter 5-6

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

FORMAL DEFINITIONS
A domain has a logical definition: A domain may have a data-type or a format defined for

it.

USA_phone_numbers are the set of 10 digit phone

numbers valid in the U.S.

The USA_phone_numbers may have a format: (ddd)-

ddd-dddd where each d is a decimal digit.

E.g., Dates have various formats such as monthname,

date, year or yyyy-mm-dd, or dd mm,yyyy etc.

Chapter 5-7

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

FORMAL DEFINITIONS
The relation is formed over the cartesian product of the sets;

each set has values from a domain Cartesian product specifies all possible combinations of values from underlying domain For example, attribute Cust-name is defined over the domain of strings of 25 characters. The role these strings play in the CUSTOMER relation is that of the name of customers. R: schema of the relation r of R: a specific "value" or population of R. R is also called the intension of a relation r is also called the extension of a relation

Chapter 5-8

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

FORMAL DEFINITIONS
Let S1 = {0,1} Let S2 = {a,b,c} Let R S1 X S2 Then for example: r(R) = {<0,a> , <0,b> , <1,c> }

is one possible state or population or extension r of the relation R, defined over domains S1 and S2. It has three tuples.
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Chapter 5-9

DEFINITION SUMMARY
Informal Terms
Table Column Row Values in a column Table Definition Populated Table

Formal Terms
Relation Attribute/Domain Tuple Domain Schema of a Relation Extension

hapter 5-10

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Example - Figure

5.1

hapter 5-11

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

CHARACTERISTICS OF RELATIONS
Ordering of tuples in a relation r(R): A relation is defined as a

set of tuples. Mathematically elements of a set have no order among them hence tuples in a relation do not have any particular order. Ordering of attributes in a relation schema R (and of values within each tuple): We will consider the attributes in R(A1, A2, ..., An) and the values in t=<v1, v2, ..., vn> to be ordered . (However, a more general alternative definition of relation does not require this ordering). Values in a tuple: All values are considered atomic (indivisible). A special null value is used to represent values that are unknown or inapplicable to certain tuples.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Relational Integrity Constraints

Constraints are conditions that must hold on all valid relation instances. The main types of constraints are:
1. 2.

3.
4.

Domain constraints Key constraints Entity integrity constraints Referential integrity constraints

hapter 5-13

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Domain Constraints
Domain constraints specify tht the value of each

attribute A must be an atomic value from the domain dom(A) The data types associated with domains typically include integer, float and character also date, time and money data types. Eg- roll no 1 to 50 cant have 60 roll no

hapter 5-14

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Key Constraints

Superkey of R: A set of attributes SK of R such that no two tuples in any valid relation instance r(R) will have the same value for SK. That is, for any distinct tuples t1 and t2 in r(R), t1[SK] t2[SK]. Key of R: A "minimal" superkey; that is, a superkey K such that removal of any attribute from K results in a set of attributes that is not a superkey.

Example: The CAR relation schema: CAR(State, Reg#, SerialNo, Make, Model, Year) has two keys Key1 = {State, Reg#}, Key2 = {SerialNo}, which are also superkeys. {SerialNo, Make} is a superkey but not a key.

If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. The primary key attributes are underlined. Eg House front door and backdoor key. Eg- pan no, emp id. To calculate slary we need emp id not pan no
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Key Constraints
5.4

hapter 5-16

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Entity Integrity
Entity Integrity: The primary key attributes of a tuple

can never be null t[PK] null for any tuple t in r(R) Note: Other attributes of R may be similarly constrained to disallow null values, even though they are not members of the primary key.

hapter 5-17

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Referential Integrity
A constraint involving two relations (the previous

hapter 5-18

constraints involve a single relation). Used to specify a relationship among tuples in two relations: the referencing relation and the referenced relation. Tuples in the referencing relation R1 have attributes FK (called foreign key attributes) that reference the primary key attributes PK of the referenced relation R2. A tuple t1 in R1 is said to reference a tuple t2 in R2 if t1[FK] = t2[PK]. In any given relation a set of attributes is called a foreign if following rules hold The attribute in the foreign key has to be the same as the primary key in other relation For every tuple in the referencing relation like dpt the attributes in its foreign key refer to existing tuples like each dpt shd hv a manager who exist in the database or it shd be null
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Referential Integrity Constraint


Statement of the constraint The value in the foreign key column (or columns) FK of the the referencing relation R1 can be

either: (1) a value of an existing primary key value of the corresponding primary key PK in the referenced relation R2,, or.. (2) a null. In case (2), the FK in R1 should not be a part of its own primary key.

hapter 5-19

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Other Types of Constraints


Semantic Integrity Constraints: - based on application semantics and cannot be expressed by the model per se - E.g., the max. no. of hours per employee for all projects he or she works on is 56 hrs per week - A constraint specification language may have to be used to express these - SQL-99 allows triggers and ASSERTIONS to allow for some of these

hapter 5-20

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

5.5

hapter 5-21

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

5.6

hapter 5-22

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

5.7

hapter 5-23

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

You might also like