DBMS 9

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Relational Model

KALINGA INSTITUTE OF INDUSTRIAL


TECHNOLOGY

School Of Computer
Engineering

Dr. Amiya Ranjan Panda,


Assistant Professor [II]
School of Computer Engineering,
Kalinga Institute of Industrial Technology (KIIT),
Deemed to be University,Odisha

4 Credit Lecture Note 09


Chapter Contents
2

 Relational Model
 Relational Database
 Relational Data Integrity
 Database Languages
 CODD’s Rule
Relational Model
3
 Relational data model is the primary data model for commercial data-
processing applications.
 A relational database consists of a collection of tables, each of which is
assigned a unique name.
 A row in a table represents a relationship among a set of values. Thus, a table is
an entity set and a row is an entity.
 The columns or properties are called attributes. For each attribute, there is a
set of permitted values, called the domain of that attribute. Same domain can be
shared by more than one attribute.
 Degree is the number of attributes in the relation/ table, where as Cardinality
is the number of tuples or rows in the relation/table.
 The attribute values are required to be atomic, i.e. indivisible.
 Let D1, D2, and D3 are the domains. Any row of the table consists of a 3-
tuple (v1, v2, v3) where v1 D1, v2 D2 and v3 D3. Thus, the table will
contain only a subset of the set of all possible rows. Therefore, the table is a
subset of D1 x D2 x D3.
 Each attribute of a relation has a unique name.
 NULL Value is a domain value which is a member of any possible domain.
Relational Model
4
 Relational data model is the primary data model for commercial data-
processing applications. Database Schema is the logical design of the database.
If (a1, a2 ...an ) be the attributes, then the relation schema will be R=(a1,a2
...an )
 Database Instance is the snapshot of the data in the database at a given instant
of time
 Relation is denoted by lower case names and Relation Schema is the name
beginning with an uppercase letter
 A relational database schema S is a set of relation schemas S = {R1, R2, ...,
Rm} and a set of integrity constraints IC. A relational database state DB of S is a
set of relation states DB = {r1, r2, ..., rm} such that each ri is a state of Ri and
such that the ri relation states satisfy the integrity constraints specified in IC.
Relational Database
5
 Relational database is a database consisting of multiple relations or tables.
The information about an enterprise is broken up into parts, with each relation
storing one part of the information
 The normalization process deals with how to design relational schemas.
Summary
6
 Attribute: Each column in a Table. Attributes are the properties which define a
relation. e.g., Student_Rollno, NAME,etc.
 Tables – In the Relational model the, relations are saved in the table format. It is
stored along with its entities. A table has two properties rows and columns. Rows
represent records and columns represent attributes.
 Tuple – It is nothing but a single row of a table, which contains a single record.
 Relation Schema: A relation schema represents the name of the relation with its
attributes.
 Degree: The total number of attributes which in the relation is called the degree of
the relation.
 Cardinality: Total number of rows present in the Table.
 Column: The column represents the set of values for a specific attribute.
 Relation instance – Relation instance is a finite set of tuples in the RDBMS system.
Relation instances never have duplicate tuples.
 Relation key - Every row has one, two or multiple attributes, which is called relation
key.
 Attribute domain – Every attribute has some pre-defined value and scope which is
known as attribute domain
Summary
7
Relational Data Integrity
8
 Candidate key is an attribute or set of attributes that can uniquely identify a
row or tuple in a table. Let R be the relation with attributes a1, a2 ... an . The
set of attributes of R is said to be a candidate key of R iff the following two
properties holds:
 Uniqueness: At any given time, no two distinct tuples or rows of R have
the same value for ai , the same value for aj...an
 Minimality: No proper subset of the set (ai , aj ... an ) has the uniqueness
property
Constraints
9
Every relation has some conditions that must hold for it to be a valid relation. These
conditions are called Relational Integrity Constraints. There are three main integrity
constraints −
1. Key constraints ( Entity Integrity Constraint/ primary Key Constraint)
2. Domain constraints
3. Referential integrity constraints
Key Constraints
There must be at least one minimal subset of attributes in the relation, which can
identify a tuple uniquely. This minimal subset of attributes is called key for that
relation. If there are more than one such minimal subsets, these are called candidate
keys.
Key constraints force that −
• in a relation with a key attribute, no two tuples can have identical values for
key attributes.
• a key attribute can not have NULL values.
Key constraints are also referred to as Entity Constraints.
Constraints
10
Entity Integrity Constraint-
 It states that no primary key value can be null. This is because the primary key is
used to identify individual tuple in the relation. So we will not be able to identify
the records uniquely containing null values for the primary key attributes. This
constraint is specified on one individual relation.
 Suppose that we denote one such subset of attributes by SK; then for any
two distinct tuples t1 and t2 in a relation state r of R, we have the constraint
that:

Example : Let R be the Table


A# B C Note:
Null B1 C1 1) „#‟ identifies the Primary key of a
A2 B2 C2 relation.
In the relation R above, the primary key
Null B3 C3 has null values in the tuples t1 & t3.
A4 B4 C3 NULL value in primary key is not
A5 B1 C5 permitted, thus, relation instance is an
invalid instance.
Domain constraints
11

Domain constraints
 Domain constraints specify that within each tuple, the value of each attribute A
must be an atomic value from the domain dom(A).
 The data types associated with domains typically include standard numeric data
types for integers (such as short integer, integer, and long integer) and real
numbers (float and double-precision float). Characters, Booleans, fixed-length
strings, and variable-length strings are also available, as are date, time, timestamp,
and money, or other special data types.
Constraints
12
3. Referential Integrity:
 In relational data model, associations between tables are defined by using
foreign keys
 A referential integrity constraint is a rule that maintains consistency
among the rows of two relations
 The rule states that if there is a foreign key in one relation, either each
foreign key value must match a primary key value in the other table or
else the foreign key value must be NULL
 A foreign key that references its own relation is known as recursive
foreign key
 The linking between the foreign key and primary key allows a set of
relations to form an integrated database
4. Operational Constraints:
 These are the constraints enforced in the database by the business rules
or real world limitations.
 The linking between the foreign key and primary key allows a set of
relations to form an integrated database
Referential Integrity:

13

R S
A# B C^ E C#
A1 B1 C1 E1 C1
A2 B2 C2
A3 B3 C3 E2 C3
A4 B4 C3 E3 C5
A5 B1 C5 E2 C2

Note:

1) “#” identifies the Primary key of a relation.

2) “^” identifies the Foreign key of a relation.

In the example above, the value of C^ in every R tuple is matching with the value of
C# in some S tuple. If a tuple having values (A6, B2, C4) is added then it is invalid
since referenced relation S doesn‟t include C4. Thus, it will be a violation of
referential integrity constraint.
Update Operations and Dealing with Constraint Violations
14
 There are three basic operations to be performed on relations:
 Insertion
 Deletion
 Update
1. The INSERT Operation:
The insert operation allows us to insert a new tuple in a relation. When we try to
insert a new record, then any of the following four types of constraints can be
violated:
 Domain constraint: If the value given to an attribute lies outside the
domain of that attribute.
 Key constraint: If the value of the key attribute in new tuple t is the same
as in the existing tuple in relation R.
 Entity Integrity constraint: If the primary key attribute value of new tuple t
is given as null.
 Referential Integrity constraint: If the value of the foreign key in t refers to
a tuple that doesn‟t appear in the referenced relation.
Update Operations and Dealing with Constraint Violations
15
Dealing with constraints violation during insertion:
If the insertion violates one or more constraints, then two options are available:
 Default option: - Insertion can be rejected and the reason of rejection can
also be explained to the user by DBMS.
 Ask the user to correct the data, resubmit, also give the reason for rejecting
the insertion.

PERSON_ID NAME AGE ADDRESS

1 Sanjay Prasad 35 b-4,Modi Nagar


2 Sharad Gupta 30 Pocket 2, Mayur
Vihar.
3 Vibhu Datt 36 c-2, New Delhi
Update Operations and Dealing with Constraint Violations
16
 (1)Insert<1, ‘Vipin’, 20, ‘Mayur Vihar’> into PERSON
Violated constraint: - Key constraint
Reason: - Primary key 1 already exists in PERSON.
Dealing: - DBMS could ask the user to provide valid PERSON_ID value and
accept the insertion if valid PERSON_ID value is provided.
 (2)Insert<’null’, ‘Anurag’, 25, ‘Patparganj’> into PERSON
Violated constraint: - Entity Integrity constraint
Reason: - Primary key is „null‟.
Dealing: - DBMS could ask the user to provide valid PERSON_ID value and
accept the insertion if valid PERSON_ID value is provided.
 (3)Insert<’abc’, ‘Suman’, 25, ‘IP college’> into PERSON
Violated constraint: - Domain constraint
Reason: - value of PERSON_ID is given a string which is not valid.
 (4)Insert <10, ‘Anu’, 25, ‘Patpatganj’> into PERSON
Violated constraint: - None
Update Operations and Dealing with Constraint Violations
17
2. The Deletion Operation:
Using the delete operation some existing records can be deleted from a relation. To
delete some specific records from the database a condition is also specified based
on which records can be selected for deletion.
Constraints that can be violated during deletion
 Only one type of constraint can be violated during deletion, it is referential
integrity constraint. It can occur when you want to delete a record in the table
where it is referenced by the foreign key of another table. Please go through the
example 8 very carefully.
 Dealing with Constraints Violation
 If the deletion violates referential integrity constraint, then three options
are available:
 Default option: - Reject the deletion. It is the job of the DBMS to explain
to the user why the deletion was rejected.
 Attempt to cascade (or propagate) the deletion by deleting tuples that
reference the tuple that is being deleted.
 Change the value of referencing attribute that causes the violation.
Delete operation
18

A# B C^
A1 B1 C1
A2 B3 C3
A3 B4 C3
A4 B1 C5
Table1 : R

Table 2:Q

C# D
C1 D1
C3 D2
C5 D3
Delete Operations and Dealing with Constraint Violations
19
 Note:
1)„#‟ identifies the Primary key of a relation.
2)„^‟ identifies the Foreign key of a relation.
 (1)Delete a tuple with C# = ‟C1‟ in Q.
 Violated constraint: - Referential Integrity constraint
 Reason: - Tuples in relation A refer to tuple in Q.
Dealing: - Options available are

1) Reject the deletion.


2) DBMS may automatically delete all tuples from relation Q and S with C #
= „C1‟. This is called cascade detection.
3) The third option would result in putting NULL value in R where C1 exist,
which is the first tuple R in the attribute C.
Update Operations and Dealing with Constraint Violations
20

 Update operations are used for modifying database values. The constraint
violations faced by this operation are logically the same as the problem faced
by Insertion and Deletion Operations. Therefore, we will not discuss this
operation in greater detail here.
Database Languages
21
 DDL (Data Definition Language)
 DDL is used to define the conceptual schema. The definition includes the
information of all the entity sets and their associated attributes as well as
the relationships between the entity sets.
 The data values stored in the database must specify certain consistency
constraints. The database systems check these constraints every time the
database is updated.
 The output of the DDL is placed in the Data Dictionary which contains the
metadata (data about data).
 The data dictionary is considered to be a special type of table, which can
only be accessed and updated by the database system itself.
 The database system consults the data dictionary, before querying or
modifying the actual data, for the validation purpose.
 CREATE, ALTER, DROP, RENAME & TRUNCATE
 DML (Data Manipulation Language)
 DML is used to manipulate data in the database.
 A query is a statement in the DML that requests the retrieval of data from
the database . SELECT, INSERT, UPDATE & DELETE
Database Languages…
22
 DCL (Data Control Languages)
 DCL allows in changing the permissions on database structures
 GRANT & REVOKE
 TCL (Transaction Control Language)
TCL allows permanently recording the changes made to the rows stored in a
table or undoing such changes
COMMIT, ROLLBACK & SAVEPOINT
CODD’s Rule
23
 Codd’s rules are a set of 12 rules proposed by E. F. Codd designed to
define what is required from a database management system in order for
it to be considered relational, i.e. RDBMS. Any database that satisfies
even six rules may be categorized as RDBMS.
 Rule0: A relational system should be able to manage databases, entirely
through its relational capabilities
 Rule1: Information representation: The entire information is explicitly
and logically represented by the data values of the tables in the
relational data model
 Rule2: Guaranteed access: In relational model, at each cell, i.e. the
interaction of each row and column, it will have one and only one value
of data (or NULL value). Each value of data must be addressable via the
combination of a table name, primary key value and the column name
 Rule3: Systematic treatment of NULL values: NULL values are
supported in fully relational DBMS for representing missing information
and inapplicable information in a systematic way independent of data
type.
CODD’s Rule
24
 Rule4: Database description rule: The database description is
represented at the logical level in the same way as ordinary data, so that
authorized users can apply the same relational language to its
interrogation as they apply to the regular data. This means, the RDBMS
should have a data dictionary
 Rule5: Comprehensive data sub-language: The RDBMS should have
its own extension of SQL. The SQL should support Data Definition, View
Definition, Data Manipulation, Integrity Constraint, and Authorization
 Rule6: Views updation: All views that are theoretically updatable are
also updatable by the system. Similarly, the views which are theoretically
non-updatable are also non-updatable by the database system.
 Rule7: High-level update, insert, deletes: A RDBMS should not only
support retrieval of data as relational sets, but should also support
insertion, updation and deletion of data as a relational set.
 Rule8: Physical data independence: Application programs and
terminal activities are not disturbed if any changes are made either in
storage representations or access methods.
CODD’s Rule
25
 Rule 9: Logical data independence: User programs and the user
should not be aware of any changes to the structure of the tables such
as the addition of extra columns
 Rule10: Distribution independence: A relational DBMS has
distribution independence. The RDBMS may spread across more than
one system and across several networks. However to the end-user, the
tables should appear no different to those that are local.
 Rule11: Integrity rule: Integrity rules must be supported by the
relational data sub-language; they can be stored in the catalogue and
not in the application program. Entity integrity: no component of a
primary key may have a NULL value. Referential integrity: for every
unique non-null ’foreign key’ values in the database, there should be a
matching primary key value from the same domain.
 Rule12: Data integrity cannot be subverted: If a relational system has
a low-level language, that low level cannot be used to subvert or bypass
the integrity rules and constraints expressed in the higher level relational
language
26

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy