DBMS and Models
DBMS and Models
DBMS and Models
A Data Base Management System is system software for easy, efficient and reliable data
processing and management. It can be used for:
Creation of a database.
Retrieval of information from the database.
Updating the database.
Managing a database.
What is a Database?
A Database is a collection of related data organized in a way that data can be easily
accessed, managed and updated. Database can be software based or hardware based, with
one sole purpose, storing data.
During early computer days, data was collected and stored on tapes, which were mostly write-
only, which means once data is stored on it, it can never be read again. They were slow and
bulky, and soon computer scientists realized that they needed a better solution to this problem.
Larry Ellison, the co-founder of Oracle was amongst the first few, who realized the need for
software based Database Management System.
A DBMS is software that allows creation, definition and manipulation of database, allowing
users to store, process and analyses data easily. DBMS provides us with an interface or a tool,
to perform various operations like creating database, storing data in it, updating data, creating
tables in the database and a lot more.
DBMS also provides protection and security to the databases. It also maintains data consistency
in case of multiple users.
MySql
Oracle
SQL Server
IBM DB2
PostgreSQL
Amazon Simple DB (cloud based) etc.
Characteristics of Database Management System
1. Data stored into Tables: Data is never directly stored into the database. Data is stored into
tables, created inside the database. DBMS also allows having relationships between tables
which makes the data more meaningful and connected. You can easily understand what
type of data is stored where by looking at all the tables created in a database.
2. Reduced Redundancy: In the modern world hard drives are very cheap, but earlier when
hard drives were too expensive, unnecessary repetition of data in database was a big
problem. But DBMS follows Normalization which divides the data in such a way that
repetition is minimum.
3. Data Consistency: On Live data, i.e. data that is being continuously updated and added,
maintaining the consistency of data can become a challenge. But DBMS handles it all by
itself.
4. Support multiple user and Concurrent Access: DBMS allows multiple users to work on
it (update, insert, and delete data) at the same time and still manages to maintain the data
consistency.
5. Query Language: DBMS provides users with a simple Query language, using which data
can be easily fetched, inserted, deleted and updated in a database.
6. Security: The DBMS also takes care of the security of data, protecting the data from un-
authorized access. In a typical DBMS, we can create user accounts with different access
permissions, using which we can easily secure our data by restricting user access.
7. DBMS supports transactions, which allows us to better handle and manage data integrity
in real world applications where multi-threading is extensively used.
Disadvantages of DBMS
Performance overhead: The use of a DBMS can add overhead to the performance of
an application, especially in cases where high levels of concurrency are required.
Cost: The cost of purchasing, maintaining and upgrading a DBMS can be high,
especially for large or complex systems.
Damaged Part: If one part of database is corrupted or damaged, then entire database
may get affected.
Compatibility: DBMS software may not be compatible with other software systems or
platforms, making it difficult to integrate with other applications.
Applications of DBMS
Banking and Finance Sector: Banks maintaining the customer details, accounts,
loans, banking transactions, credit card transactions. Finance: Storing the information
about sales and holdings, purchasing of financial stocks and bonds.
The database management system can be divided into five major components, they are:
1. Hardware
2. Software
3. Data
4. Procedures
5. Database Access Language
Let's have a simple diagram to see how they all fit together to form a database management
system.
Question: - Difference Between File system and DBMS.
Only one user can access data at a Multiple users can access data at a
User Access time. time.
The users are not required to write The user has to write procedures for
Meaning procedures. managing databases
In a typical file processing system, each department has its own files, designed especially for
those applications. The department itself works with the data processing staff, sets policies or
standards for the format and maintenance of its files.
1) Data redundancy
In computer system many files are likely in the different formats and the programs are written
in different programming languages. Moreover, the same information may be duplicated in
several files, this duplication of data is known as data redundancy.
Example: If you store the same data item more than once in a database, that is data redundancy
2) Data inconsistency
Various copies contain the same type of data which may no longer which means that various
copies of same data may contain different kind of information.
Example: For example, if a student’s record in the database has 2 home telephone numbers;
consumers of the data will be unable to determine which phone numbers to use.
In file processing system it is very difficult to access the data in a specific way and it also
require a special application program which carry out new task.
DDL is the short name for Data Definition Language, which deals with database schemas and
descriptions, of how the data should reside in the database.
CREATE: to create a database and its objects like (table, index, views, store procedure,
function, and triggers)
TRUNCATE: remove all records from a table, including all spaces allocated for the
records are removed
DML is the short name for Data Manipulation Language which deals with data manipulation
and includes most common SQL statements such SELECT, INSERT, UPDATE, DELETE, etc.,
and it is used to store, modify, retrieve, delete and update data in a database. Data query
language(DQL) is the subset of “Data Manipulation Language”. The most common command
of DQL is SELECT statement. SELECT statement help on retrieving the data from the table
without changing anything in the table.
1. Object based logical model: - These model are used in describing data at logical and
view levels.
Entity-relationship Model
Hierarchical Model
Network Model
Relational Model
3. Physical data model: - describe the behaviour of the data at the disk level.
The Entity Relationship Model is a model for identifying entities to be represented in the
database and representation of how those entities are related. The ER data model specifies
enterprise schema that represents the overall logical structure of a database graphically.
Peter Chen developed the ER diagram in 1976. The ER model was created to provide a simple
and understandable model for representing the structure and logic of databases.
ER diagrams represent the E-R model in a database, making them easy to convert into
relations (tables).
ER diagrams provide the purpose of real-world modelling of objects which makes them
intently useful.
ER Model is used to model the logical view of the system from a data perspective which
consists of these symbols:
Lines: Lines represent attributes to entities and entity sets with other relationship types.
What is Entity?
An Entity may be an object with a physical existence – a particular person, car, house, or
employee – or it may be an object with a conceptual existence – a company, a job, or a
university course.
Types of Entity
1. Strong Entity
A Strong Entity is a type of entity that has a key Attribute. Strong Entity does not depend on
other Entity in the Schema. It has a primary key, that helps in identifying it uniquely, and it is
represented by a rectangle. These are called Strong Entity Types.
2. Weak Entity
An Entity type has a key attribute that uniquely identifies each entity in the entity set. But some
entity type exists for which key attributes can’t be defined. These are called Weak Entity types .
For Example, A company may store the information of dependents (Parents, Children,
Spouse) of an Employee. But the dependents can’t exist without the employee. So Dependent
will be a Weak Entity Type and Employee will be Identifying Entity type for Dependent,
which means it is Strong Entity Type .
What is Attributes?
Attributes are the properties that define the entity type. For example, Roll_No, Name, DOB,
Age, Address, and Mobile_No are the attributes that define entity type Student. In ER diagram,
the attribute is represented by an oval.
Attribute
Types of Attributes
1. Key Attribute
The attribute which uniquely identifies each entity in the entity set is called the key attribute.
For example, Roll_No will be unique for each student. In ER diagram, the key attribute is
represented by an oval with underlying lines.
Key Attribute
2. Composite Attribute
An attribute composed of many other attributes is called a composite attribute. For example,
the Address attribute of the student Entity type consists of Street, City, State, and Country. In
ER diagram, the composite attribute is represented by an oval comprising of ovals.
Composite Attribute
3. Multivalued Attribute
An attribute consisting of more than one value for a given entity. For example, Phone_No (can
be more than one for a given student). In ER diagram, a multivalued attribute is represented by
a double oval.
Multivalued Attribute
4. Derived Attribute
An attribute that can be derived from other attributes of the entity type is known as a derived
attribute. e.g.; Age (can be derived from DOB). In ER diagram, the derived attribute is
represented by a dashed oval.
Derived Attribute
The Complete Entity Type Student with its Attributes can be represented as:
The number of times an entity of an entity set participates in a relationship set is known
as cardinality . Cardinality can be of different types:
1. One-to-One: When each entity in each entity set can take part only once in the relationship,
the cardinality is one-to-one. Let us assume that a male can marry one female and a female can
marry one male. So the relationship will be one-to-one.
.
one to one cardinality
2. One-to-Many: In one-to-many mapping as well where each entity can be related to more
than one entity and the total number of tables that can be used in this is 2. Let us assume that
one surgeon department can accommodate many doctors. So the Cardinality will be 1 to M. It
means one department has many Doctors.
3. Many-to-One: When entities in one entity set can take part only once in the relationship set
and entities in other entity sets can take part more than once in the relationship set, cardinality
is many to one. Let us assume that a student can take only one course but one course can be
taken by many students. So the cardinality will be n to 1. It means that for one course there can
be n students but for one student, there will be only one course.
4. Many-to-Many: When entities in all entity sets can take part more than once in the
relationship cardinality is many to many. Let us assume that a student can take more than one
course and one course can be taken by many students. So the relationship will be many to many.
Hierarchical Model
This database model organizes data into a tree-like-structure, with a single root, to which all
the other data is linked. The hierarchy starts from the Root data, and expands like a tree, adding
child nodes to the parent nodes.
In this model, a child node will only have a single parent node.
This model efficiently describes many real-world relationships like index of a book, recipes
etc.
In hierarchical model, data is organised into tree-like structure with one one-to-many
relationship between two different types of data, for example, one department can have
many courses, many professors and of-course many students.
Network Model
So, the subject has two parent classes. STUDENT has one child and Degree class also have
one child.
This kind of relationship among entities represents the network model.
Characteristics of the network model
There are many characteristics of the network model, some of these characteristics are
mentioned below;
1. The network model is better than a hierarchical model.
2. Supports many to many relationships.
3. Many parents can have many children.
4. Many children can have many parents (as shown in the figure).
5. Entities are represented as a connected network with each other.
6. One child entity can have more than one parent entity
7. Represented as a network and one child can have more than one parent. This model
represents a complex structure.
8. Entities can have multiple parent entities and leads to a complex structure.
9. Not very flexible to reorganize the model.
10. High performance
11. Query facility is not available in the network model.
Relational model makes the query much easier than in hierarchical or network database
systems. In 1970, E.F Codd has been developed it. A relational database is defined as a group
of independent tables which are linked to each other using some common fields of each related
table. This model can be represented as a table with columns and rows. Each row is known as
a tuple. Each table of the column has a name or attribute. It is well knows in database
technology because it is usually used to represent real-world objects and the relationships
between them. Some popular relational databases are used nowadays like Oracle, Sybase, DB2,
MySQL Server etc.
Relation Table
List of the following basic operations that can be performed on a relational model:
o Insertion Operation
o Deletion Operation
o Update Operation
o Retrieval Operation
Types of key in DBMS:-
For example: In Student table, ID is used as a key because it is unique for each student. In
PERSON table, passport_number, license_number, SSN are keys since they are unique for
each person.
1. Primary key
o It is the first key which is used to identify one and only one instance of an entity
uniquely. An entity can contain multiple keys as we saw in PERSON table. The key
which is most suitable from those lists become a primary key.
o In the EMPLOYEE table, ID can be primary key since it is unique for each employee.
In the EMPLOYEE table, we can even select License_Number and Passport_Number
as primary key since they are also unique.
o For each entity, selection of the primary key is based on requirement and
developers.
2. Candidate key
o A candidate key is an attribute or set of an attribute which can uniquely identify a tuple.
o The remaining attributes except for primary key are considered as a candidate key. The
candidate keys are as strong as the primary key.
o
For example: In the EMPLOYEE table, id is best suited for the primary key. Rest of the
attributes like SSN, Passport_Number, and License_Number, etc. are considered as a candidate
key.
3. Super Key
Super key is a set of an attribute which can uniquely identify a tuple. Super key is a superset
of a candidate key.
4. Foreign key
o Foreign keys are the column of the table which is used to point to the primary key of
another table.
o In a company, every employee works in a specific department, and employee and
department are two different entities. So we can't store the information of the
department in the employee table. That's why we link these two tables through the
primary key of one table.
o We add the primary key of the DEPARTMENT table, Department_Id as a new attribute
in the EMPLOYEE table.
o Now in the EMPLOYEE table, Department_Id is the foreign key, and both the tables
are related.
BY ONE EXAMPLE SHOW THREE DIFFERENT KEYS:-
1. Primary Key
The primary key refers to a column or a set of columns of a table that helps us identify all the
records uniquely present in that table. A table can consist of just one primary key. Also, this
primary key cannot consist of the same values reappearing/repeating for any of its rows. All
the values of a primary key have to be different, and there should be no repetitions.
2. Super Key
A super key refers to the set of all those keys that help us uniquely identify all the rows present
in a table. It means that all of these columns present in a table that can identify the columns of
that table uniquely act as the super keys.
3. Candidate Key
The candidate keys refer to those attributes that identify rows uniquely in a table. In a table, we
select the primary key from a candidate key. Thus, a candidate key has similar properties as
that of the primary keys that we have explained above. In a table, there can be multiple
candidate keys.
4. Foreign Key
We use a foreign key to establish relationships between two available tables. The foreign key
would require every value present in a column/set of columns to match the referential table’s
primary key. A foreign key helps us to maintain data as well as referential integrity.