Unit -1-Database Management System (KCS501)

 

Database Management System (KCS501)

Unit -1

Introduction:

What is Database

The database is a collection of inter-related data which is used to retrieve, insert and delete the data efficiently. It is also used to organize the data in the form of a table, schema, views, and reports, etc.

For example: The college Database organizes the data about the admin, staff, students and faculty etc.

Using the database, you can easily retrieve, insert, and delete the information.

Database Management System

  • Database management system is a software which is used to manage the database. For example: MySQLOracle, etc are a very popular commercial database which is used in different applications.
  • DBMS provides an interface to perform various operations like database creation, storing data in it, updating data, creating a table in the database and a lot more.

DBMS allows users the following tasks:

  • Data Definition: It is used for creation, modification, and removal of definition that defines the organization of data in the database.
  • Data Updation: It is used for the insertion, modification, and deletion of the actual data in the database.
  • Data Retrieval: It is used to retrieve the data from the database which can be used by applications for various purposes.
  • User Administration: It is used for registering and monitoring users, maintain data integrity, enforcing data security, dealing with concurrency control, monitoring performance and recovering information corrupted by unexpected failure.

Characteristics of DBMS

  • It uses a digital repository established on a server to store and manage the information.
  • It can provide a clear and logical view of the process that manipulates data.
  • DBMS contains automatic backup and recovery procedures.
  • It contains ACID properties which maintain data in a healthy state in case of failure.
  • It can reduce the complex relationship between data.
  • It is used to support manipulation and processing of data.
  • It is used to provide security of data.
  • It can view the database from different viewpoints according to the requirements of the user.

Advantages of DBMS

  • Controls database redundancy: It can control data redundancy because it stores all the data in one single database file and that recorded data is placed in the database.
  • Data sharing: In DBMS, the authorized users of an organization can share the data among multiple users.
  • Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
  • Reduce time: It reduces development time and maintenance need.
  • Backup: It provides backup and recovery subsystems which create automatic backup of data from hardware and software failures and restores the data if required.
  • multiple user interface: It provides different types of user interfaces like graphical user interfaces, application program interfaces

Disadvantages of DBMS

  • Cost of Hardware and Software: It requires a high speed of data processor and large memory size to run DBMS software.
  • Size: It occupies a large space of disks and large memory to run them efficiently.
  • Complexity: Database system creates additional complexity and requirements.
  • Higher impact of failure: Failure is highly impacted the database because in most of the organization, all the data stored in a single database and if the database is damaged due to electric failure or database corruption then the data may be lost forever.

Types of Databases

There are various types of databases used for storing different varieties of data:

Types of Databases

1) Centralized Database

It is the type of database that stores data at a centralized database system. It comforts the users to access the stored data from different locations through several applications. These applications contain the authentication process to let users access data securely. An example of a Centralized database can be Central Library that carries a central database of each library in a college/university.

Advantages of Centralized Database

  • It has decreased the risk of data management, i.e., manipulation of data will not affect the core data.
  • Data consistency is maintained as it manages data in a central repository.
  • It provides better data quality, which enables organizations to establish data standards.
  • It is less costly because fewer vendors are required to handle the data sets.

Disadvantages of Centralized Database

  • The size of the centralized database is large, which increases the response time for fetching the data.
  • It is not easy to update such an extensive database system.
  • If any server failure occurs, entire data will be lost, which could be a huge loss.

2) Distributed Database

Unlike a centralized database system, in distributed systems, data is distributed among different database systems of an organization. These database systems are connected via communication links. Such links help the end-users to access the data easily. Examples of the Distributed database are Apache Cassandra, HBase, Ignite, etc.

We can further divide a distributed database system into:

Types of Databases

  • Homogeneous DDB: Those database systems which execute on the same operating system and use the same application process and carry the same hardware devices.
  • Heterogeneous DDB: Those database systems which execute on different operating systems under different application procedures, and carries different hardware devices.

Advantages of Distributed Database

  • Modular development is possible in a distributed database, i.e., the system can be expanded by including new computers and connecting them to the distributed system.
  • One server failure will not affect the entire data set.

3) Relational Database

This database is based on the relational data model, which stores data in the form of rows(tuple) and columns(attributes), and together forms a table(relation). A relational database uses SQL for storing, manipulating, as well as maintaining the data. E.F. Codd invented the database in 1970. Each table in the database carries a key that makes the data unique from others. Examples of Relational databases are MySQL, Microsoft SQL Server, Oracle, etc.

Properties of Relational Database

There are following four commonly known properties of a relational model known as ACID properties, where:

A means Atomicity: This ensures the data operation will complete either with success or with failure. It follows the 'all or nothing' strategy. For example, a transaction will either be committed or will abort.

C means Consistency: If we perform any operation over the data, its value before and after the operation should be preserved. For example, the account balance before and after the transaction should be correct, i.e., it should remain conserved.

I means Isolation: There can be concurrent users for accessing data at the same time from the database. Thus, isolation between the data should remain isolated. For example, when multiple transactions occur at the same time, one transaction effects should not be visible to the other transactions in the database.

D means Durability: It ensures that once it completes the operation and commits the data, data changes should remain permanent.

4) NoSQL Database

Non-SQL/Not Only SQL is a type of database that is used for storing a wide range of data sets. It is not a relational database as it stores data not only in tabular form but in several different ways. It came into existence when the demand for building modern applications increased. Thus, NoSQL presented a wide variety of database technologies in response to the demands. We can further divide a NoSQL database into the following four types:

Types of Databases

a.              Key-value storage: It is the simplest type of database storage where it stores every single item as a key (or attribute name) holding its value, together.

  1. Document-oriented Database: A type of database used to store data as JSON-like document. It helps developers in storing data by using the same document-model format as used in the application code.
  2. Graph Databases: It is used for storing vast amounts of data in a graph-like structure. Most commonly, social networking websites use the graph database.
  3. Wide-column stores: It is similar to the data represented in relational databases. Here, data is stored in large columns together, instead of storing in rows.

Advantages of NoSQL Database

  • It enables good productivity in the application development as it is not required to store data in a structured format.
  • It is a better option for managing and handling large data sets.
  • It provides high scalability.
  • Users can quickly access data from the database through key-value.

5) Cloud Database

A type of database where data is stored in a virtual environment and executes over the cloud computing platform. It provides users with various cloud computing services (SaaS, PaaS, IaaS, etc.) for accessing the database. There are numerous cloud platforms, but the best options are:

  • Amazon Web Services(AWS)
  • Microsoft Azure
  • Kamatera
  • PhonixNAP
  • ScienceSoft
  • Google Cloud SQL, etc.

6) Object-oriented Databases

The type of database that uses the object-based data model approach for storing data in the database system. The data is represented and stored as objects which are similar to the objects used in the object-oriented programming language.

7) Hierarchical Databases

It is the type of database that stores data in the form of parent-children relationship nodes. Here, it organizes data in a tree-like structure.

Types of Databases

Data get stored in the form of records that are connected via links. Each child record in the tree will contain only one parent. On the other hand, each parent record can have multiple child records.

8) Network Databases

It is the database that typically follows the network data model. Here, the representation of data is in the form of nodes connected via links between them. Unlike the hierarchical database, it allows each record to have multiple children and parent nodes to form a generalized graph structure.

9) Personal Database

Collecting and storing data on the user's system defines a Personal Database. This database is basically designed for a single user.

Advantage of Personal Database

  • It is simple and easy to handle.
  • It occupies less storage space as it is small in size.

10) Operational Database

The type of database which creates and updates the database in real-time. It is basically designed for executing and handling the daily data operations in several businesses. For example, An organization uses operational databases for managing per day transactions.

11) Enterprise Database

Large organizations or enterprises use this database for managing a massive amount of data. It helps organizations to increase and improve their efficiency. Such a database allows simultaneous access to users.

Advantages of Enterprise Database:

  • Multi processes are supportable over the Enterprise database.
  • It allows executing parallel queries on the system.

Difference between File System and DBMS

File System Approach

File based systems were an early attempt to computerize the manual system. It is also called a traditional based approach in which a decentralized approach was taken where each department stored and controlled its own data with the help of a data processing specialist. The main role of a data processing specialist was to create the necessary computer file structures, and also manage the data within structures and design some application programs that create reports based on file data.

DBMS vs. File System

In the above figure:

Consider an example of a student's file system. The student file will contain information regarding the student (i.e. roll no, student name, course etc.). Similarly, we have a subject file that contains information about the subject and the result file which contains the information regarding the result.

Some fields are duplicated in more than one file, which leads to data redundancy. So to overcome this problem, we need to create a centralized system, i.e. DBMS approach.

DBMS:

A database approach is a well-organized collection of data that are related in a meaningful way which can be accessed by different users but stored only once in a system. The various operations performed by the DBMS system are: Insertion, deletion, selection, sorting etc.

DBMS vs. File System

In the above figure,

In the above figure, duplication of data is reduced due to centralization of data.

There are the following differences between DBMS and File systems:

Basis

DBMS Approach

File System Approach

Meaning

DBMS is a collection of data. In DBMS, the user is not required to write the procedures.

The file system is a collection of data. In this system, the user has to write the procedures for managing the database.

Sharing of data

Due to the centralized approach, data sharing is easy.

Data is distributed in many files, and it may be of different formats, so it isn't easy to share data.

Data Abstraction

DBMS gives an abstract view of data that hides the details.

The file system provides the detail of the data representation and storage of data.

Security and Protection

DBMS provides a good protection mechanism.

It isn't easy to protect a file under the file system.

Recovery Mechanism

DBMS provides a crash recovery mechanism, i.e., DBMS protects the user from system failure.

The file system doesn't have a crash mechanism, i.e., if the system crashes while entering some data, then the content of the file will be lost.

Manipulation Techniques

DBMS contains a wide variety of sophisticated techniques to store and retrieve the data.

The file system can't efficiently store and retrieve the data.

Concurrency Problems

DBMS takes care of Concurrent access of data using some form of locking.

In the File system, concurrent access has many problems like redirecting the file while deleting some information or updating some information.

Where to use

Database approach used in large systems which interrelate many files.

File system approach used in large systems which interrelate many files.

Cost

The database system is expensive to design.

The file system approach is cheaper to design.

Data Redundancy and Inconsistency

Due to the centralization of the database, the problems of data redundancy and inconsistency are controlled.

In this, the files and application programs are created by different programmers so that there exists a lot of duplication of data which may lead to inconsistency.

Structure

The database structure is complex to design.

The file system approach has a simple structure.

Data Independence

In this system, Data Independence exists, and it can be of two types.

  • Logical Data Independence
  • Physical Data Independence

In the File system approach, there exists no Data Independence.

Integrity Constraints

Integrity Constraints are easy to apply.

Integrity Constraints are difficult to implement in file system.

Data Models

In the database approach, 3 types of data models exist:

  • Hierarchal data models
  • Network data models
  • Relational data models

In the file system approach, there is no concept of data models exists.

Flexibility

Changes are often a necessity to the content of the data stored in any system, and these changes are more easily with a database approach.

The flexibility of the system is less as compared to the DBMS approach.

Examples

Oracle, SQL Server, Sybase etc.

Cobol, C++ etc.

 

 

DBMS Architecture

  • The DBMS design depends upon its architecture. The basic client/server architecture is used to deal with a large number of PCs, web servers, database servers and other components that are connected with networks.
  • The client/server architecture consists of many PCs and a workstation which are connected via the network.
  • DBMS architecture depends upon how users are connected to the database to get their request done.

Types of DBMS Architecture


DBMS Architecture

Database architecture can be seen as a single tier or multi-tier. But logically, database architecture is of two types like: 2-tier architecture and 3-tier architecture.

1-Tier Architecture

  • In this architecture, the database is directly available to the user. It means the user can directly sit on the DBMS and uses it.
  • Any changes done here will directly be done on the database itself. It doesn't provide a handy tool for end users.
  • The 1-Tier architecture is used for development of the local application, where programmers can directly communicate with the database for the quick response.

2-Tier Architecture

  • The 2-Tier architecture is same as basic client-server. In the two-tier architecture, applications on the client end can directly communicate with the database at the server side. For this interaction, API's like: ODBCJDBC are used.
  • The user interfaces and application programs are run on the client-side.
  • The server side is responsible to provide the functionalities like: query processing and transaction management.
  • To communicate with the DBMS, client-side application establishes a connection with the server side.


DBMS Architecture

Fig: 2-tier Architecture

3-Tier Architecture

  • The 3-Tier architecture contains another layer between the client and server. In this architecture, client can't directly communicate with the server.
  • The application on the client-end interacts with an application server which further communicates with the database system.
  • End user has no idea about the existence of the database beyond the application server. The database also has no idea about any other user beyond the application.
  • The 3-Tier architecture is used in case of large web application.


DBMS Architecture

Fig: 3-tier Architecture

Three schema Architecture

  • The three schema architecture is also called ANSI/SPARC architecture or three-level architecture.
  • This framework is used to describe the structure of a specific database system.
  • The three schema architecture is also used to separate the user applications and physical database.
  • The three schema architecture contains three-levels. It breaks the database down into three different categories.

The three-schema architecture is as follows:

DBMS Three schema Architecture

In the above diagram:

  • It shows the DBMS architecture.
  • Mapping is used to transform the request and response between various database levels of architecture.
  • Mapping is not good for small DBMS because it takes more time.
  • In External / Conceptual mapping, it is necessary to transform the request from external level to conceptual schema.
  • In Conceptual / Internal mapping, DBMS transform the request from the conceptual to internal level.

Objectives of Three schema Architecture

The main objective of three level architecture is to enable multiple users to access the same data with a personalized view while storing the underlying data only once. Thus it separates the user's view from the physical structure of the database. This separation is desirable for the following reasons:

  • Different users need different views of the same data.
  • The approach in which a particular user needs to see the data may change over time.
  • The users of the database should not worry about the physical implementation and internal workings of the database such as data compression and encryption techniques, hashing, optimization of the internal structures etc.
  • All users should be able to access the same data according to their requirements.
  • DBA should be able to change the conceptual structure of the database without affecting the user's
  • Internal structure of the database should be unaffected by changes to physical aspects of the storage.

1. Internal Level

DBMS Three schema Architecture

  • The internal level has an internal schema which describes the physical storage structure of the database.
  • The internal schema is also known as a physical schema.
  • It uses the physical data model. It is used to define that how the data will be stored in a block.
  • The physical level is used to describe complex low-level data structures in detail.

The internal level is generally is concerned with the following activities:

  • Storage space allocations.
    For Example: B-Trees, Hashing etc.
  • Access paths.
    For Example: Specification of primary and secondary keys, indexes, pointers and sequencing.
  • Data compression and encryption techniques.
  • Optimization of internal structures.
  • Representation of stored fields.

2. Conceptual Level

DBMS Three schema Architecture

  • The conceptual schema describes the design of a database at the conceptual level. Conceptual level is also known as logical level.
  • The conceptual schema describes the structure of the whole database.
  • The conceptual level describes what data are to be stored in the database and also describes what relationship exists among those data.
  • In the conceptual level, internal details such as an implementation of the data structure are hidden.
  • Programmers and database administrators work at this level.

3. External Level

DBMS Three schema Architecture

  • At the external level, a database contains several schemas that sometimes called as subschema. The subschema is used to describe the different view of the database.
  • An external schema is also known as view schema.
  • Each view schema describes the database part that a particular user group is interested and hides the remaining database from that user group.
  • The view schema describes the end user interaction with database systems.

Mapping between Views

The three levels of DBMS architecture don't exist independently of each other. There must be correspondence between the three levels i.e. how they actually correspond with each other. DBMS is responsible for correspondence between the three types of schema. This correspondence is called Mapping.

There are basically two types of mapping in the database architecture:

  • Conceptual/ Internal Mapping
  • External / Conceptual Mapping

Conceptual/ Internal Mapping

The Conceptual/ Internal Mapping lies between the conceptual level and the internal level. Its role is to define the correspondence between the records and fields of the conceptual level and files and data structures of the internal level.

External/ Conceptual Mapping

The external/Conceptual Mapping lies between the external level and the Conceptual level. Its role is to define the correspondence between a particular external and the conceptual view.

Data Models

Data Model is the modeling of the data description, data semantics, and consistency constraints of the data. It provides the conceptual tools for describing the design of a database at each level of data abstraction. Therefore, there are following four data models used for understanding the structure of the database:

Data Models

1) Relational Data Model: This type of model designs the data in the form of rows and columns within a table. Thus, a relational model uses tables for representing data and in-between relationships. Tables are also called relations. This model was initially described by Edgar F. Codd, in 1969. The relational data model is the widely used model which is primarily used by commercial data processing applications.

2) Entity-Relationship Data Model: An ER model is the logical representation of data as objects and relationships among them. These objects are known as entities, and relationship is an association among these entities. This model was designed by Peter Chen and published in 1976 papers. It was widely used in database designing. A set of attributes describe the entities. For example, student_name, student_id describes the 'student' entity. A set of the same type of entities is known as an 'Entity set', and the set of the same type of relationships is known as 'relationship set'.

3) Object-based Data Model: An extension of the ER model with notions of functions, encapsulation, and object identity, as well. This model supports a rich type system that includes structured and collection types. Thus, in 1980s, various database systems following the object-oriented approach were developed. Here, the objects are nothing but the data carrying its properties.

4) Semistructured Data Model: This type of data model is different from the other three data models (explained above). The semistructured data model allows the data specifications at places where the individual data items of the same type may have different attributes sets. The Extensible Markup Language, also known as XML, is widely used for representing the semistructured data. Although XML was initially designed for including the markup information to the text document, it gains importance because of its application in the exchange of data.

Data model Schema and Instance

  • The data which is stored in the database at a particular moment of time is called an instance of the database.
  • The overall design of a database is called schema.
  • A database schema is the skeleton structure of the database. It represents the logical view of the entire database.
  • A schema contains schema objects like table, foreign key, primary key, views, columns, data types, stored procedure, etc.
  • A database schema can be represented by using the visual diagram. That diagram shows the database objects and relationship with each other.
  • A database schema is designed by the database designers to help programmers whose software will interact with the database. The process of database creation is called data modeling.

A schema diagram can display only some aspects of a schema like the name of record type, data type, and constraints. Other aspects can't be specified through the schema diagram. For example, the given figure neither show the data type of each data item nor the relationship among various files.

In the database, actual data changes quite frequently. For example, in the given figure, the database changes whenever we add a new grade or add a student. The data at a particular moment of time is called the instance of the database.

DBMS Data model Schema and Instance

Data Independence

  • Data independence can be explained using the three-schema architecture.
  • Data independence refers characteristic of being able to modify the schema at one level of the database system without altering the schema at the next higher level.

There are two types of data independence:

1. Logical Data Independence

  • Logical data independence refers characteristic of being able to change the conceptual schema without having to change the external schema.
  • Logical data independence is used to separate the external level from the conceptual view.
  • If we do any changes in the conceptual view of the data, then the user view of the data would not be affected.
  • Logical data independence occurs at the user interface level.

2. Physical Data Independence

  • Physical data independence can be defined as the capacity to change the internal schema without having to change the conceptual schema.
  • If we do any changes in the storage size of the database system server, then the Conceptual structure of the database will not be affected.
  • Physical data independence is used to separate conceptual levels from the internal levels.
  • Physical data independence occurs at the logical interface level.


DBMS Data Independence

Fig: Data Independence

Database Languages in DBMS

  • A DBMS has appropriate languages and interfaces to express database queries and updates.
  • Database languages can be used to read, store and update the data in the database.

Types of Database Languages


DBMS Language

1. Data Definition Language (DDL)

  • DDL stands for Data Definition Language. It is used to define database structure or pattern.
  • It is used to create schema, tables, indexes, constraints, etc. in the database.
  • Using the DDL statements, you can create the skeleton of the database.
  • Data definition language is used to store the information of metadata like the number of tables and schemas, their names, indexes, columns in each table, constraints, etc.

Here are some tasks that come under DDL:

  • Create: It is used to create objects in the database.
  • Alter: It is used to alter the structure of the database.
  • Drop: It is used to delete objects from the database.
  • Truncate: It is used to remove all records from a table.
  • Rename: It is used to rename an object.
  • Comment: It is used to comment on the data dictionary.

These commands are used to update the database schema that's why they come under Data definition language.

2. Data Manipulation Language (DML)

DML stands for Data Manipulation Language. It is used for accessing and manipulating data in a database. It handles user requests.

Here are some tasks that come under DML:

  • Select: It is used to retrieve data from a database.
  • Insert: It is used to insert data into a table.
  • Update: It is used to update existing data within a table.
  • Delete: It is used to delete all records from a table.
  • Merge: It performs UPSERT operation, i.e., insert or update operations.
  • Call: It is used to call a structured query language or a Java subprogram.
  • Explain Plan: It has the parameter of explaining data.
  • Lock Table: It controls concurrency.

3. Data Control Language (DCL)

  • DCL stands for Data Control Language. It is used to retrieve the stored or saved data.
  • The DCL execution is transactional. It also has rollback parameters.

(But in Oracle database, the execution of data control language does not have the feature of rolling back.)

Here are some tasks that come under DCL:

  • Grant: It is used to give user access privileges to a database.
  • Revoke: It is used to take back permissions from the user.

There are the following operations which have the authorization of Revoke:

CONNECT, INSERT, USAGE, EXECUTE, DELETE, UPDATE and SELECT.

4. Transaction Control Language (TCL)

TCL is used to run the changes made by the DML statement. TCL can be grouped into a logical transaction.

Here are some tasks that come under TCL:

  • Commit: It is used to save the transaction on the database.
  • Rollback: It is used to restore the database to original since the last Commit.

ACID Properties in DBMS

DBMS is the management of data that should remain integrated when any changes are done in it. It is because if the integrity of the data is affected, whole data will get disturbed and corrupted. Therefore, to maintain the integrity of the data, there are four properties described in the database management system, which are known as the ACID properties. The ACID properties are meant for the transaction that goes through a different group of tasks, and there we come to see the role of the ACID properties.

In this section, we will learn and understand about the ACID properties. We will learn what these properties stand for and what does each property is used for. We will also understand the ACID properties with the help of some examples.

ACID Properties

The expansion of the term ACID defines for:

ACID Properties in DBMS

1) Atomicity

The term atomicity defines that the data remains atomic. It means if any operation is performed on the data, either it should be performed or executed completely or should not be executed at all. It further means that the operation should not break in between or execute partially. In the case of executing operations on the transaction, the operation should be completely executed and not partially.

Example: If Remo has account A having $30 in his account from which he wishes to send $10 to Sheero's account, which is B. In account B, a sum of $ 100 is already present. When $10 will be transferred to account B, the sum will become $110. Now, there will be two operations that will take place. One is the amount of $10 that Remo wants to transfer will be debited from his account A, and the same amount will get credited to account B, i.e., into Sheero's account. Now, what happens - the first operation of debit executes successfully, but the credit operation, however, fails. Thus, in Remo's account A, the value becomes $20, and to that of Sheero's account, it remains $100 as it was previously present.

ACID Properties in DBMS

In the above diagram, it can be seen that after crediting $10, the amount is still $100 in account B. So, it is not an atomic transaction.

The below image shows that both debit and credit operations are done successfully. Thus the transaction is atomic.

ACID Properties in DBMS

Thus, when the amount loses atomicity, then in the bank systems, this becomes a huge issue, and so the atomicity is the main focus in the bank systems.

2) Consistency

The word consistency means that the value should remain preserved always. In DBMS, the integrity of the data should be maintained, which means if a change in the database is made, it should remain preserved always. In the case of transactions, the integrity of the data is very essential so that the database remains consistent before and after the transaction. The data should always be correct.

Example:

ACID Properties in DBMS

In the above figure, there are three accounts, A, B, and C, where A is making a transaction T one by one to both B & C. There are two operations that take place, i.e., Debit and Credit. Account A firstly debits $50 to account B, and the amount in account A is read $300 by B before the transaction. After the successful transaction T, the available amount in B becomes $150. Now, A debits $20 to account C, and that time, the value read by C is $250 (that is correct as a debit of $50 has been successfully done to B). The debit and credit operation from account A to C has been done successfully. We can see that the transaction is done successfully, and the value is also read correctly. Thus, the data is consistent. In case the value read by B and C is $300, which means that data is inconsistent because when the debit operation executes, it will not be consistent.

3) Isolation

The term 'isolation' means separation. In DBMS, Isolation is the property of a database where no data should affect the other one and may occur concurrently. In short, the operation on one database should begin when the operation on the first database gets complete. It means if two operations are being performed on two different databases, they may not affect the value of one another. In the case of transactions, when two or more transactions occur simultaneously, the consistency should remain maintained. Any changes that occur in any particular transaction will not be seen by other transactions until the change is not committed in the memory.

Example: If two operations are concurrently running on two different accounts, then the value of both accounts should not get affected. The value should remain persistent. As you can see in the below diagram, account A is making T1 and T2 transactions to account B and C, but both are executing independently without affecting each other. It is known as Isolation.

ACID Properties in DBMS

4) Durability

Durability ensures the permanency of something. In DBMS, the term durability ensures that the data after the successful execution of the operation becomes permanent in the database. The durability of the data should be so perfect that even if the system fails or leads to a crash, the database still survives. However, if gets lost, it becomes the responsibility of the recovery manager for ensuring the durability of the database. For committing the values, the COMMIT command must be used every time we make changes.

Therefore, the ACID property of DBMS plays a vital role in maintaining the consistency and availability of data in the database.

Thus, it was a precise introduction of ACID properties in DBMS. We have discussed these properties in the transaction section also.

ER (Entity Relationship) Diagram in DBMS

  • ER model stands for an Entity-Relationship model. It is a high-level data model. This model is used to define the data elements and relationship for a specified system.
  • It develops a conceptual design for the database. It also develops a very simple and easy to design view of data.
  • In ER modeling, the database structure is portrayed as a diagram called an entity-relationship diagram.

For example, Suppose we design a school database. In this database, the student will be an entity with attributes like address, name, id, age, etc. The address can be another entity with attributes like city, street name, pin code, etc and there will be a relationship between them.


DBMS ER model concept

Component of ER Diagram


DBMS ER model concept

1. Entity:

An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as rectangles.

Consider an organization as an example- manager, product, employee, department etc. can be taken as an entity.


DBMS ER model concept

a. Weak Entity


DBMS ER model concept

2. Attribute

The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.

For example, id, age, contact number, name, etc. can be attributes of a student.


DBMS ER model concept



a. Key Attribute

The key attribute is used to represent the main characteristics of an entity. It represents a primary key. The key attribute is represented by an ellipse with the text underlined.


DBMS ER model concept

b. Composite Attribute

An attribute that composed of many other attributes is known as a composite attribute. The composite attribute is represented by an ellipse, and those ellipses are connected with an ellipse.


DBMS ER model concept

c. Multivalued Attribute

An attribute can have more than one value. These attributes are known as a multivalued attribute. The double oval is used to represent multivalued attribute.

For example, a student can have more than one phone number.


DBMS ER model concept

d. Derived Attribute

An attribute that can be derived from other attribute is known as a derived attribute. It can be represented by a dashed ellipse.

For example, A person's age changes over time and can be derived from another attribute like Date of birth.


DBMS ER model concept

3. Relationship

A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the relationship.


DBMS ER model concept

Types of relationship are as follows:

a. One-to-One Relationship

When only one instance of an entity is associated with the relationship, then it is known as one to one relationship.

For example, A female can marry to one male, and a male can marry to one female.


DBMS ER model concept

b. One-to-many relationship

When only one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then this is known as a one-to-many relationship.

For example, Scientist can invent many inventions, but the invention is done by the only specific scientist.


DBMS ER model concept

c. Many-to-one relationship

When more than one instance of the entity on the left, and only one instance of an entity on the right associates with the relationship then it is known as a many-to-one relationship.

For example, Student enrolls for only one course, but a course can have many students.


DBMS ER model concept

d. Many-to-many relationship

When more than one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then it is known as a many-to-many relationship.

For example, Employee can assign by many projects and project can have many employees.


DBMS ER model concept

Notation of ER diagram

Database can be represented using the notations. In ER diagram, many notations are used to express the cardinality. These notations are as follows:


DBMS Notation of ER diagram

Fig: Notations of ER diagram

Cardinality in DBMS (Mapping Constraints)

DBMS

DBMS stands for Database Management System, which is a tool, or a software used to do various operations on a Database like the Creation of the Database, Deletion of the Database, or Updating the current Database. To simplify processing and data querying, the most popular types of Databases currently in use typically model their data as rows and columns in a set of tables. The data may then be handled, updated, regulated, and structured with ease. For writing and querying data, most Databases employ Structured Query Language (SQL).

Cardinality

Cardinality means how the entities are arranged to each other or what is the relationship structure between entities in a relationship set. In a Database Management System, Cardinality represents a number that denotes how many times an entity is participating with another entity in a relationship set. The Cardinality of DBMS is a very important attribute in representing the structure of a Database. In a table, the number of rows or tuples represents the Cardinality.

Cardinality Ratio

Cardinality ratio is also called Cardinality Mapping, which represents the mapping of one entity set to another entity set in a relationship set. We generally take the example of a binary relationship set where two entities are mapped to each other.

Cardinality is very important in the Database of various businesses. For example, if we want to track the purchase history of each customer then we can use the one-to-many cardinality to find the data of a specific customer. The Cardinality model can be used in Databases by Database Managers for a variety of purposes, but corporations often use it to evaluate customer or inventory data.

There are four types of Cardinality Mapping in Database Management Systems:

  1. One to one
  2. Many to one
  3. One to many
  4. Many to many

One to One

One to one cardinality is represented by a 1:1 symbol. In this, there is at most one relationship from one entity to another entity. There are a lot of examples of one-to-one cardinality in real life databases.

For example, one student can have only one student id, and one student id can belong to only one student. So, the relationship mapping between student and student id will be one to one cardinality mapping.

Another example is the relationship between the director of the school and the school because one school can have a maximum of one director, and one director can belong to only one school.

Note: it is not necessary that there would be a mapping for all entities in an entity set in one-to-one cardinality. Some entities cannot participate in the mapping.

DBMS Mapping Constraints

Many to One Cardinality:

In many to one cardinality mapping, from set 1, there can be multiple sets that can make relationships with a single entity of set 2. Or we can also describe it as from set 2, and one entity can make a relationship with more than one entity of set 1.

One to one Cardinality is the subset of Many to one Cardinality. It can be represented by M:1.

For example, there are multiple patients in a hospital who are served by a single doctor, so the relationship between patients and doctors can be represented by Many to one Cardinality.

DBMS Mapping Constraints

One to Many Cardinalities:

In One-to-many cardinality mapping, from set 1, there can be a maximum single set that can make relationships with a single or more than one entity of set 2. Or we can also describe it as from set 2, more than one entity can make a relationship with only one entity of set 1.

One to one cardinality is the subset of One-to-many Cardinality. It can be represented by 1: M.

For Example, in a hospital, there can be various compounders, so the relationship between the hospital and compounders can be mapped through One-to-many Cardinality.

DBMS Mapping Constraints

Many to Many Cardinalities:

In many, many cardinalities mapping, there can be one or more than one entity that can associate with one or more than one entity of set 2. In the same way from the end of set 2, one or more than one entity can make a relation with one or more than one entity of set 1.

It is represented by M: N or N: M.

One to one cardinality, One to many cardinalities, and Many to one cardinality is the subset of the many to many cardinalities.

For Example, in a college, multiple students can work on a single project, and a single student can also work on multiple projects. So, the relationship between the project and the student can be represented by many to many cardinalities.

DBMS Mapping Constraints

Appropriate Mapping Cardinality

Evidently, the real-world context in which the relation set is modeled determines the Appropriate Mapping Cardinality for a specific relation set.

  • We can combine relational tables with many involved tables if the Cardinality is one-to-many or many-to-one.
  • One entity can be combined with a relation table if it has a one-to-one relationship and total participation, and two entities can be combined with their relation to form a single table if both of them have total participation.
  • We cannot mix any two tables if the Cardinality is many-to-many.

Keys

  • Keys play an important role in the relational database.
  • It is used to uniquely identify any record or row of data from the table. It is also used to establish and identify relationships between tables.

For example, ID is used as a key in the Student table because it is unique for each student. In the PERSON table, passport_number, license_number, SSN are keys since they are unique for each person.

DBMS Keys

Types of keys:

DBMS Keys

1. Primary key

  • It is the first key used to identify one and only one instance of an entity uniquely. An entity can contain multiple keys, as we saw in the PERSON table. The key which is most suitable from those lists becomes a primary key.
  • In the EMPLOYEE table, ID can be the primary key since it is unique for each employee. In the EMPLOYEE table, we can even select License_Number and Passport_Number as primary keys since they are also unique.
  • For each entity, the primary key selection is based on requirements and developers.

DBMS Keys

2. Candidate key

  • A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
  • Except for the primary key, the remaining attributes are considered a candidate key. The candidate keys are as strong as the primary key.

For example: In the EMPLOYEE table, id is best suited for the primary key. The rest of the attributes, like SSN, Passport_Number, License_Number, etc., are considered a candidate key.

DBMS Keys

3. Super Key

Super key is an attribute set that can uniquely identify a tuple. A super key is a superset of a candidate key.

DBMS Keys

For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME), the name of two employees can be the same, but their EMPLYEE_ID can't be the same. Hence, this combination can also be a key.

The super key would be EMPLOYEE-ID (EMPLOYEE_ID, EMPLOYEE-NAME), etc.

4. Foreign key

  • Foreign keys are the column of the table used to point to the primary key of another table.
  • Every employee works in a specific department in a company, and employee and department are two different entities. So we can't store the department's information in the employee table. That's why we link these two tables through the primary key of one table.
  • We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in the EMPLOYEE table.
  • In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.

DBMS Keys

5. Alternate key

There may be one or more attributes or a combination of attributes that uniquely identify each tuple in a relation. These attributes or combinations of the attributes are called the candidate keys. One key is chosen as the primary key from these candidate keys, and the remaining candidate key, if it exists, is termed the alternate key. In other words, the total number of the alternate keys is the total number of candidate keys minus the primary key. The alternate key may or may not exist. If there is only one candidate key in a relation, it does not have an alternate key.

For example, employee relation has two attributes, Employee_Id and PAN_No, that act as candidate keys. In this relation, Employee_Id is chosen as the primary key, so the other candidate key, PAN_No, acts as the Alternate key.

DBMS Keys

6. Composite key

Whenever a primary key consists of more than one attribute, it is known as a composite key. This key is also known as Concatenated Key.

DBMS Keys

For example, in employee relations, we assume that an employee may be assigned multiple roles, and an employee may work on multiple projects simultaneously. So the primary key will be composed of all three attributes, namely Emp_ID, Emp_role, and Proj_ID in combination. So these attributes act as a composite key since the primary key comprises more than one attribute.

DBMS Keys

7. Artificial key

The key created using arbitrarily assigned data are known as artificial keys. These keys are created when a primary key is large and complex and has no relationship with many other relations. The data values of the artificial keys are usually numbered in a serial order.

For example, the primary key, which is composed of Emp_ID, Emp_role, and Proj_ID, is large in employee relations. So it would be better to add a new virtual attribute to identify each tuple in the relation uniquely.

Generalization

  • Generalization is like a bottom-up approach in which two or more entities of lower level combine to form a higher level entity if they have some attributes in common.
  • In generalization, an entity of a higher level can also combine with the entities of the lower level to form a further higher level entity.
  • Generalization is more like subclass and superclass system, but the only difference is the approach. Generalization uses the bottom-up approach.
  • In generalization, entities are combined to form a more generalized entity, i.e., subclasses are combined to make a superclass.

For example, Faculty and Student entities can be generalized and create a higher level entity Person.


DBMS Generalization

Specialization

  • Specialization is a top-down approach, and it is opposite to Generalization. In specialization, one higher level entity can be broken down into two lower level entities.
  • Specialization is used to identify the subset of an entity set that shares some distinguishing characteristics.
  • Normally, the superclass is defined first, the subclass and its related attributes are defined next, and relationship set are then added.

For example: In an Employee management system, EMPLOYEE entity can be specialized as TESTER or DEVELOPER based on what role they play in the company.


DBMS SpecializationAggregation

In aggregation, the relation between two entities is treated as a single entity. In aggregation, relationship with its corresponding entities is aggregated into a higher level entity.

For example: Center entity offers the Course entity act as a single entity in the relationship which is in a relationship with another entity visitor. In the real world, if a visitor visits a coaching center then he will never enquiry about the Course only or just about the Center instead he will ask the enquiry about both.


DBMS AggregationReduction of ER diagram to Table

The database can be represented using the notations, and these notations can be reduced to a collection of tables.

In the database, every entity set or relationship set can be represented in tabular form.

The ER diagram is given below:


DBMS Reduction of ER diagram to Table

There are some points for converting the ER diagram to the table:

  • Entity type becomes a table.

In the given ER diagram, LECTURE, STUDENT, SUBJECT and COURSE forms individual tables.

  • All single-valued attribute becomes a column for the table.

In the STUDENT entity, STUDENT_NAME and STUDENT_ID form the column of STUDENT table. Similarly, COURSE_NAME and COURSE_ID form the column of COURSE table and so on.

  • A key attribute of the entity type represented by the primary key.

In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and LECTURE_ID are the key attribute of the entity.

  • The multivalued attribute is represented by a separate table.

In the student table, a hobby is a multivalued attribute. So it is not possible to represent multiple values in a single column of STUDENT table. Hence we create a table STUD_HOBBY with column name STUDENT_ID and HOBBY. Using both the column, we create a composite key.

  • Composite attribute represented by components.

In the given ER diagram, student address is a composite attribute. It contains CITY, PIN, DOOR#, STREET, and STATE. In the STUDENT table, these attributes can merge as an individual column.

  • Derived attributes are not considered in the table.

In the STUDENT table, Age is the derived attribute. It can be calculated at any point of time by calculating the difference between current date and Date of Birth.

Using these rules, you can convert the ER diagram to tables and columns and assign the mapping between the tables. Table structure for the given ER diagram is as below:


DBMS Reduction of ER diagram to Table

Figure: Table structure

elationship of higher degree

The degree of relationship can be defined as the number of occurrences in one entity that is associated with the number of occurrences in another entity.

There is the three degree of relationship:

  1. One-to-one (1:1)
  2. One-to-many (1:M)
  3. Many-to-many (M:N)

1. One-to-one

  • In a one-to-one relationship, one occurrence of an entity relates to only one occurrence in another entity.
  • A one-to-one relationship rarely exists in practice.
  • For example: if an employee is allocated a company car then that car can only be driven by that employee.
  • Therefore, employee and company car have a one-to-one relationship.


DBMS Relationship of higher degree

2. One-to-many

  • In a one-to-many relationship, one occurrence in an entity relates to many occurrences in another entity.
  • For example: An employee works in one department, but a department has many employees.
  • Therefore, department and employee have a one-to-many relationship.


DBMS Relationship of higher degree

3. Many-to-many

  • In a many-to-many relationship, many occurrences in an entity relate to many occurrences in another entity.
  • Same as a one-to-one relationship, the many-to-many relationship rarely exists in practice.
  • For example: At the same time, an employee can work on several projects, and a project has a team of many employees.
  • Therefore, employee and project have a many-to-many relationship.


DBMS Relationship of higher degree

Comments

Popular posts from this blog

Compiler Design UNIT-1

COA- Unit -5 Peripheral DeviceS

COA-UNIT-3 Control Unit