DBMS 9
DBMS 9
DBMS 9
School Of Computer
Engineering
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:
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:
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.
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
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