Rdbms Fundamentals
Rdbms Fundamentals
I. INTRODUCING DATABASES :
Concept of a Database :
Traditional Approach : In this approach, independent application programs access their own independent
data files. This results in many problems in data storage and retrieval.
Database Approach : In this approach, all application access a common database, which is a centralized
data storage system.
Database Management System (DBMS) : DBMS is a software that interfaces between applications and a
database for all data processing activities.
Users of a DBMS : End Users, Application Programmers and Database Administrators use a DBMS, either
directly or indirectly. How users interact with a Database :
1. End users send queries to the DBMS through applications.
2. The DBMS translates the queries.
3. The DBMS retrieves data from the database.
4. The DBMS sends data to the application, which present the data to the end users.
Functions of a DBMS :
Function of DBMS Description Provided by using
Defining the data structure Defining structure of data to be stored in database Data Definition Language
(DDL)
Manipulating Data Retrieving, adding, modifying, deleting data. Data Manipulation Language (DML)
Data Security Preventing unauthorized access to data. User-ids and Passwords.
Control of Data Access Allowing users to use only relevant data Data Control Language (DCL)
Architecture of a Database :
Need for an Architecture : The details about complexity and structure of data in a database in not required
by end-users. Therefore, differentiating what the end-users see and what is actually there in a database is
important. Architecture of a Database : The architecture of a database comprises a set of three levels at
which a database can be viewed.
External Level or View, Conceptual Level or View & Internal Level or View.
Relational Database Management System (RDBMS) : RDBMS is the most popular form of DBMS used in
the world. It uses a relational database to organize data. A relational database comprise relations, which are
represented as tables.
Relation : A relation stores information about an object in the real world. A relation is represented as a table.
Attribute : Each attribute of a relation stores a piece of information about an object. Attributes are
represented as columns in a tables and can be arranged in any order. Each attribute in a relation is unique
and contain atomic values i.e. Atomic value contain a single value of data and Non-Atomic values contain a
set of values. The number of attributes in a relation is called the degree of the relation.
Tuple : A row in a table is called a tuple of the relation. The number of tuples in a relation is known as the
cardinality of the relation. Tuples in a table are unique and can be arranged in any order.
Domain : A domain is a set of valid atomic values that an attribute can take. Within a single database, an
attribute cannot have different domains associated with it. A domain can include a null value, if the value for
the domain is unknown or does not exist.
Entity : An entity is an object that exists in the real world and is distinguishable from other objects. Each
entity is represented as a table in a relational database.
Types of Entities : Entities can be classified in two ways - based on existence and based on subsets. Based
on existence, entities can be classified as Dominant and Weak entities. Based on subsets, entities can be
classifies as Supertypes and Subtypes.
Types of Relationships : Relationships are classified into three types based on the occurrence of the related
entities. One-to-One(1-1), One-to-Many(1-M) & Many-to-Many(M-M).
Using E/R Diagram : A E/R diagram represent entities and relationships in a database system.
Normalization : Normalization is a formal process of developing data structures in a manner that eliminates
redundancy and promotes integrity. You need to simplify structure of data in relations for easy storage and
retrieval. The process of simplifying relations is called normalization. The new relations that are obtained
after normalization are called normalized relations.
Conversion from 1NF to 2NF : To convert a relation in 1NF to 2NF, move all nonkey attributes that are not
wholly dependent on the primary key, to a new relation. Then, choose an appropriate primary key for the
new relation. E.g. Separating Sup. table and Item table.
Transitively Dependent Attributes : Transitively Dependent Attributes in a relation are those that are
dependent on a nonkey attribute and not the primary key. To simplify data to 3NF, you ensure that there are
no attributes in a relation that are transitively dependent on other attributes.
Conversion from 2NF to 3NF : To convert a relation in 2NF to 3NF, move all transitively dependent attributes
to a new relation. Then, choose an appropriate primary key for the new relation. E.g. Status is dependent on
City in Sup. table, so move those two to separate table.
Simplifying Data to 4NF (Isolate Independent Multiple Relationships) :
SQL :SQL is the language that provides command to interact with the data in the database. SQL consists of
three components - DDL, DML & DCL.
DDL : DDL comprises commands you can use to create and modify the database structure.
DML : DML comprises commands you can use to add, modify, delete and query data in the database.
DCL : DCL comprises commands you can use to control the user access to the database.
Integrity Constraints : Integrity constraints allows only correct changes to be made to a database. There are
two types of integrity constraints - entity integrity and referential integrity.
Entity Integrity : Entity Integrity ensures that for each row in a table, the value of the primary key is unique
and is not null.
Referential Integrity : Referential Integrity ensures that for each row in a table, the value of the foreign key is
present in the reference table.
Commit : Commit is an SQL command that indicates the successful end of a transaction. After an RDBMS
executes this command all the changes are made to the database.
Rollback : Rollback is an SQL command that cancels a transaction before it is complete. The rollback
command removes the changes of all previous commands in a transaction from the buffer.
Lost Update Problem : Lost update problem occurs when an update made by a transaction is lost due to an
update made by another transaction.
Uncommitted Data Problem : Uncommitted data problem occurs when a transaction accesses data that has
been updated by a previous transaction that has not yet ended.
Inconsistent Data Problem : Inconsistent data problem occurs when a transaction accesses data from the
database and simultaneously another transaction is changing that data.
Locking : Locking is a facility provided by an RDBMS to ensure that a transaction does not interfere with any
other transaction. Locking prevents the problem of lost update, uncommitted data and inconsistent data. An
RDBMS provided two types of locks for locking a part of the database - shared locks and exclusive locks.
Shared Locks : If a transaction is only reading data from a database, it gets a shared lock on that part of the
database. Other transactions can also get a shared lock on that part of the database to read data. However,
they cannot change the data.
Exclusive Locks : If a transaction is updating data in a database, it gets an exclusive lock on that part of the
database. No other transaction can read or change this data.
.