Unit 1 Basic of DBMS
Unit 1 Basic of DBMS
In this article, we will explain the key concepts, benefits, and types of Database Management
Systems (DBMS). We’ll also cover how DBMS solutions work, why they’re important for modern
applications, and what features they offer to ensure data integrity, security, and efficient retrieval.
What is a DBMS?
A DBMS is a system that allows users to create, modify, and query databases while ensuring data
integrity, security, and efficient data access. Unlike traditional file systems, DBMS minimizes data
redundancy, prevents inconsistencies, and simplifies data management with features like concurrent
access and backup mechanisms. It organizes data into tables, views, schemas, and reports, providing
a structured approach to data management.
Example:
A university database can store and manage student information, faculty records, and administrative
data, allowing seamless retrieval, insertion, and deletion of information as required.
1. Data Modeling: Tools to create and modify data models, defining the structure and
relationships within the database.
2. Data Storage and Retrieval: Efficient mechanisms for storing data and executing queries to
retrieve it quickly.
3. Concurrency Control: Ensures multiple users can access the database simultaneously
without conflicts.
4. Data Integrity and Security: Enforces rules to maintain accurate and secure data, including
access controls and encryption.
5. Backup and Recovery: Protects data with regular backups and enables recovery in case of
system failures
6. Types of DBMS
7. There are several types of Database Management Systems (DBMS), each tailored
to different data structures, scalability requirements, and application needs. The
most common types are as follows:-
1. Relational Database Management System (RDBMS)
RDBMS organizes data into tables (relations) composed of rows and columns. It
uses primary keys to uniquely identify rows and foreign keys to establish
relationships between tables. Queries are written in SQL (Structured Query
Language), which allows for efficient data manipulation and retrieval.
Examples: MySQL, Oracle, Microsoft SQL Server and Postgre SQL.
2. NoSQL DBMS
NoSQL systems are designed to handle large-scale data and provide high
performance for scenarios where relational models might be restrictive. They
store data in various non-relational formats, such as key-value
pairs, documents, graphs, or columns. These flexible data models enable rapid
scaling and are well-suited for unstructured or semi-structured data.
Examples: MongoDB, Cassandra, DynamoDB and Redis.
3. Object-Oriented DBMS (OODBMS)
OODBMS integrates object-oriented programming concepts into the database
environment, allowing data to be stored as objects. This approach supports
complex data types and relationships, making it ideal for applications requiring
advanced data modeling and real-world simulations.
Examples: ObjectDB, db4o.
Database Languages
Database languages are specialized sets of commands and instructions used to
define, manipulate, and control data within a database. Each language type plays
a distinct role in database management, ensuring efficient storage, retrieval, and
security of data. The primary database languages include:
1. Data Definition Language (DDL)
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)
• ALTER: alters the structure of the existing database
• DROP: delete objects from the database
• TRUNCATE: remove all records from a table, including all spaces allocated for the
records are removed
• COMMENT: add comments to the data dictionary
• RENAME: rename an object
2. Data Manipulation Language (DML)
DML focuses on manipulating the data stored in the database, enabling users to
retrieve, add, update, and delete data.
• SELECT: retrieve data from a database
• INSERT: insert data into a table
• UPDATE: updates existing data within a table
• DELETE: Delete all records from a database table
• MERGE: UPSERT operation (insert or update)
• CALL: call a PL/SQL or Java subprogram
• EXPLAIN PLAN: interpretation of the data access path
• LOCK TABLE: concurrency Control
3. Data Control Language (DCL)
DCL commands manage access permissions, ensuring data security by controlling
who can perform certain actions on the database.
• GRANT: Provides specific privileges to a user (e.g., SELECT, INSERT).
• REVOKE: Removes previously granted permissions from a user.
4. Transaction Control Language (TCL)
TCL commands oversee transactional data to maintain consistency, reliability, and
atomicity.
• ROLLBACK: Undoes changes made during a transaction.
• COMMIT: Saves all changes made during a transaction.
• SAVEPOINT: Sets a point within a transaction to which one can later roll back.
5. Data Query Language (DQL)
DQL is a subset of DML, specifically focused on data retrieval.
• SELECT: The primary DQL command, used to query data from the database without
altering its structure or contents.
Paradigm Shift from File System to DBMS
Before the advent of modern Database Management Systems (DBMS), data was
managed using basic file systems on hard drives. While this approach allowed
users to store, retrieve, and update files as needed, it came with numerous
challenges.
A typical example can be seen in a file-based university management system,
where data was stored in separate sections such as Departments, Academics,
Results, Accounts, and Hostels. Certain information like student names and
phone numbers was repeated across multiple files, leading to the following
issues:
1. Redundancy of data
When the same data exists in multiple places, any update must be manually
repeated everywhere. For instance, if a student changes their phone number, it
must be updated across all sections. Failure to do so leads to unnecessary
duplication and wasted storage.
2. Inconsistency of Data
Data is said to be inconsistent if multiple copies of the same data do not match
each other. If the Phone number is different in Accounts Section and Academics
Section, it will be inconsistent. Inconsistency may be because of typing errors or
not updating all copies of the same data.
3. Complex Data Access
A user should know the exact location of the file to access data, so the process is
very cumbersome and tedious. If the user wants to search the student hostel
allotment number of a student from 10000 unsorted students’ records, how
difficult it can be.
4. Lack of Security
File systems provided limited control over who could access certain data. A
student who gained access to a file with grades might easily alter it without
proper authorization, compromising data integrity.
5. No Concurrent Access
File systems were not designed for multiple users working at the same time. If
one user was editing a file, others had to wait, which hindered collaboration and
slowed down workflows.
6. No Backup and Recovery
File systems lacked built-in mechanisms for creating backups or recovering data
after a loss. If a file was accidentally deleted or corrupted, there was no easy way
to restore it, potentially causing permanent data loss.
Advantages of DBMS
1. Data organization: A DBMS allows for the organization and storage of data in a
structured manner, making it easy to retrieve and query the data as needed.
2. Data integrity: A DBMS provides mechanisms for enforcing data integrity
constraints, such as constraints on the values of data and access controls that
restrict who can access the data.
3. Concurrent access: A DBMS provides mechanisms for controlling concurrent
access to the database, to ensure that multiple users can access the data without
conflicting with each other.
4. Data security: A DBMS provides tools for managing the security of the data, such
as controlling access to the data and encrypting sensitive data.
5. Backup and recovery: A DBMS provides mechanisms for backing up and recovering
the data in the event of a system failure.
6. Data sharing: A DBMS allows multiple users to access and share the same data,
which can be useful in a collaborative work environment.
Disadvantages of DBMS
1. Complexity: DBMS can be complex to set up and maintain, requiring specialized
knowledge and skills.
2. 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.
3. Scalability: The use of a DBMS can limit the scalability of an application, since it
requires the use of locking and other synchronization mechanisms to ensure data
consistency.
4. Cost: The cost of purchasing, maintaining and upgrading a DBMS can be high,
especially for large or complex systems.
5. Limited Use Cases: Not all use cases are suitable for a DBMS, some solutions don’t
need high reliability, consistency or security and may be better served by other
types of data storage.
Applications of DBMS
1. Enterprise Information: Sales, accounting, human resources, Manufacturing, online
retailers.
2. 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.
3. University: Maintaining the information about student course enrolled information,
student grades, staff roles.
4. Airlines: Reservations and schedules.
5. Telecommunications: Prepaid, postpaid bills maintance.
Security File systems provide less security in DBMS has more security mechanisms
Constraints comparison to DBMS. as compared to file systems.
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
The main difference between a file system and a DBMS (Database Management System) is the way
they organize and manage data.
1. File systems are used to manage files and directories, and provide basic operations for
creating, deleting, renaming, and accessing files. They typically store data in a hierarchical
structure, where files are organized in directories and subdirectories. File systems are simple
and efficient, but they lack the ability to manage complex data relationships and ensure data
consistency.
2. On the other hand, DBMS is a software system designed to manage large amounts of
structured data, and provide advanced operations for storing, retrieving, and manipulating
data. DBMS provides a centralized and organized way of storing data, which can be accessed
and modified by multiple users or applications. DBMS offers advanced features like data
validation, indexing , transactions, concurrency control , and backup and recovery
mechanisms. DBMS ensures data consistency, accuracy, and integrity by enforcing data
constraints, such as primary keys, foreign keys, and data types.
In summary, file systems are suitable for managing small amounts of unstructured data , while DBMS
is designed for managing large amounts of structured data, and offers more advanced features for
ensuring data integrity, security, and performance.
• 1-Tier Architecture
• 2-Tier Architecture
• 3-Tier Architecture
1-Tier Architecture
In 1-Tier Architecture the database is directly available to the user, the user can directly sit on the
DBMS and use it that is, the client, server, and Database are all present on the same machine. This
setup is simple and is often used in personal or standalone applications where the user interacts
directly with the database.
For Example: A Microsoft Excel spreadsheet is a great example of one-tier architecture.
• Everything—the user interface, application logic and data is handled on a single system.
• The user directly interacts with the application, performs operations like calculations or data
entry and stores data locally on the same machine.
This architecture is simple and works well for personal, standalone applications where no external
server or network connection is needed.
• Simple Architecture: 1-Tier Architecture is the most simple architecture to set up, as only a
single machine is required to maintain it.
• Easy to Implement: 1-Tier Architecture can be easily deployed, and hence it is mostly used in
small projects.
2-Tier Architecture
The 2-tier architecture is similar to a basic client-server model . The application at the client end
directly communicates with the database on the server side. APIs like ODBC and JDBC are used for
this interaction. The server side is responsible for providing query processing and transaction
management functionalities. On the client side, the user interfaces and application programs are run.
The application on the client side establishes a connection with the server side to communicate with
the DBMS.
For Example: A Library Management System used in schools or small organizations is a classic
example of two-tier architecture.
1. Client Layer (Tier 1): This is the user interface that library staff or users interact with. For
example they might use a desktop application to search for books, issue them, or check due
dates.
2. Database Layer (Tier 2): The database server stores all the library records such as book
details, user information, and transaction logs.
The client layer sends a request (like searching for a book) to the database layer which processes it
and sends back the result. This separation allows the client to focus on the user interface, while the
server handles data storage and retrieval.
• Easy to Access: 2-Tier Architecture makes easy access to the database, which makes fast
retrieval.
• Scalable: We can scale the database easily, by adding clients or upgrading hardware.
• Low Cost: 2-Tier Architecture is cheaper than 3-Tier Architecture and Multi-Tier
Architecture .
• Simple: 2-Tier Architecture is easily understandable as well as simple because of only two
components.
3-Tier Architecture
In 3-Tier Architecture , there is another layer between the client and the server. The client does not
directly communicate with the server. Instead, it interacts with an application server which further
communicates with the database system and then the query processing and transaction
management takes place. This intermediate layer acts as a medium for the exchange of partially
processed data between the server and the client. This type of architecture is used in the case of
large web applications.
For Example: E-commerce Store
User: You visit an online store, search for a product and add it to your cart.
Processing: The system checks if the product is in stock, calculates the total price and applies any
discounts.
Database: The product details, your cart and order history are stored in the database for future
reference.
• Data Integrity: 3-Tier Architecture maintains Data Integrity. Since there is a middle layer
between the client and the server, data corruption can be avoided/removed.
• Security: 3-Tier Architecture Improves Security. This type of model prevents direct
interaction of the client with the server thereby reducing access to unauthorized data.
• Difficult to Interact: It becomes difficult for this sort of interaction to take place due to the
presence of middle layers.
views of data-levels of abstraction:-
Database systems comprise complex data structures. In order to make the system efficient in terms
of retrieval of data, and reduce complexity in terms of usability of users, developers use abstraction
i.e. hide irrelevant details from the users. This approach simplifies database design.
This is the lowest level of data abstraction. It tells us how the data is actually stored in memory.
Access methods like sequential or random access and file organization methods like B+ trees and
hashing are used for the same. Usability, size of memory, and the number of times the records are
factors that we need to know while designing the database.
Suppose we need to store the details of an employee. Blocks of storage and the amount of memory
used for these purposes are kept hidden from the user.
This level comprises the information that is actually stored in the database in the form of tables. It
also stores the relationship among the data entities in relatively simple structures. At this level, the
information available to the user at the view level is unknown.
We can store the various attributes of an employee and relationships, e.g. with the manager can also
be stored.
The logical level thus describes the entire database in terms of a small number of relatively simple
structures. Although implementation of the simple structures at the logical level may involve
complex physical-level structures, the user of the logical level does not need to be aware of this
complexity. This is referred to as physical data independence. Database administrators, who must
decide what information to keep in the database, use the logical level of abstraction.
This is the highest level of abstraction. Only a part of the actual database is viewed by the users. This
level exists to ease the accessibility of the database by an individual user. Users view data in the form
of rows and columns. Tables and relations are used to store data. Multiple views of the same
database may exist. Users can just view the data and interact with the database, storage and
implementation details are hidden from them. Even though the logical level uses simpler structures,
complexity remains because of the variety of information stored in a large database. Many users of
the database system do not need all this information; instead, they need to access only a part of the
database. The view level of abstraction exists to simplify their interaction with the system
• Logical level – it will contain the fields and the attributes of data.
• View level – it works with CLI or GUI access of database
The main purpose of data abstraction is to achieve data independence in order to save the time and
cost required when the database is modified or altered.
Data Independence
Data Independence is mainly defined as a property of DBMS that helps you to change the database
schema at one level of a system without requiring to change the schema at the next level. it helps to
keep the data separated from all program that makes use of it.
We have namely two levels of data independence arising from these levels of abstraction:
It refers to the characteristic of being able to modify the physical schema without any alterations to
the conceptual or logical schema, done for optimization purposes, e.g., the Conceptual structure of
the database would not be affected by any change in storage size of the database system server.
Changing from sequential to random access files is one such example. These alterations or
modifications to the physical structure may include:
It refers characteristic of being able to modify the logical schema without affecting the external
schema or application program. The user view of the data would not be affected by any changes to
the conceptual view of the data. These changes may include insertion or deletion of attributes,
altering table structures entities or relationships to the logical schema, etc.
Data models:-
A Data Model in Database Management System (DBMS) is the concept of tools that are developed
to summarize the description of the database. Data Models provide us with a transparent picture of
data which helps us in creating an actual database. It shows us from the design of the data to its
proper implementation of data.
The conceptual data model describes the database at a very high level and is useful to understand
the needs or requirements of the database. It is this model, that is used in the requirement-gathering
process i.e. before the Database Designers start making a particular database. One such popular
model is the entity/relationship model (ER model). The E/R model specializes in entities,
relationships, and even attributes that are used by database designers. In terms of this concept, a
discussion can be made even with non-computer science(non-technical) users and stakeholders, and
their requirements can be understood.
Entity-Relationship Model( ER Model): It is a high-level data model which is used to define the data
and the relationships between them. It is basically a conceptual design of any database which is easy
to design the view of data.
Components of ER Model:
1. Entity: An entity is referred to as a real-world object. It can be a name, place, object, class,
etc. These are represented by a rectangle in an ER Diagram.
2. Attributes: An attribute can be defined as the description of the entity. These are
represented by Ellipse in an ER Diagram. It can be Age, Roll Number, or Marks for a Student.
3. Relationship: Relationships are used to define relations among different entities. Diamonds
and Rhombus are used to show Relationships.
• This type of Data Models are designed and developed for a business audience.
Conceptual data models known as Domain models create a common vocabulary for all stakeholders
by establishing basic concepts and scope
This type of data model is used to represent only the logical part of the database and does not
represent the physical structure of the database. The representational data model allows us to focus
primarily, on the design part of the database. A popular representational model is a Relational
model. The relational Model consists of Relational Algebra and Relational Calculus. In the Relational
Model, we basically use tables to represent our data and the relationships between them. It is a
theoretical concept whose practical implementation is done in Physical Data Model.
The advantage of using a Representational data model is to provide a foundation to form the base for
the Physical model.
• Relational models like Relational Algebra and Relational Calculus are commonly used.
The physical Data Model is used to practically implement Relational Data Model. Ultimately, all data
in a database is stored physically on a secondary storage device such as discs and tapes. This is stored
in the form of files, records, and certain other data structures. It has all the information on the
format in which the files are present and the structure of the databases, the presence of external
data structures, and their relation to each other. Here, we basically save tables in memory so they
can be accessed efficiently. In order to come up with a good physical model, we have to work on the
relational model in a better way. Structured Query Language (SQL) is used to practically implement
Relational Algebra.
This Data Model describes HOW the system will be implemented using a specific DBMS system. This
model is typically created by DBA and developers. The purpose is actual implementation of the
database.
Characteristics of a physical data model:
• The physical data model describes data need for a single project or application though it
maybe integrated with other physical data models based on project scope.
• Data Model contains relationships between tables that which addresses cardinality and
nullability of the relationships.
• Developed for a specific version of a DBMS, location, data storage or technology to be used
in the project.
• Columns should have exact datatypes, lengths assigned and default values.
• Primary and Foreign keys, views, indexes, access profiles, and authorizations, etc. are defined
1. Hierarchical Model
The hierarchical Model is one of the oldest models in the data model which was developed by IBM,
in the 1950s. In a hierarchical model, data are viewed as a collection of tables, or we can say
segments that form a hierarchical relation. In this, the data is organized into a tree-like structure
where each record consists of one parent record and many children. Even if the segments are
connected as a chain-like structure by logical associations, then the instant structure can be a fan
structure with multiple branches. We call the illogical associations as directional associations.
2. Network Model
The Network Model was formalized by the Database Task group in the 1960s. This model is the
generalization of the hierarchical model. This model can consist of multiple parent segments and
these segments are grouped as levels but there exists a logical association between the segments
belonging to any level. Mostly, there exists a many-to-many logical association between any of the
two segments.
In the Object-Oriented Data Model, data and their relationships are contained in a single structure
which is referred to as an object in this data model. In this, real-world problems are represented as
objects with different attributes. All objects have multiple relationships between them. Basically, it is
a combination of Object Oriented programming and a Relational Database Model.
The float data model basically consists of a two-dimensional array of data models that do not contain
any duplicate elements in the array. This data model has one drawback it cannot store a large
amount of data that is the tables can not be of large size.
The Context data model is simply a data model which consists of more than one data model. For
example, the Context data model consists of ER Model, Object-Oriented Data Model, etc. This model
allows users to do more than one thing which each individual data model can do.
2. It helps us in finding the missing data and also in minimizing Data Redundancy.
4. The data model should be detailed enough to be used for building the physical database.
5. The information in the data model can be used for defining the relationship between tables,
primary and foreign keys, and stored procedures.
1. In the case of a vast database, sometimes it becomes difficult to understand the data model.
2. You must have the proper knowledge of SQL to use physical models.
3. Even smaller change made in structure require modification in the entire application.
5. To develop Data model one should know physical data stored characteristics.
What is Schema?
Schema is the overall description of the database. The basic structure of how the data will be stored
in the database is called schema. In DBMS, the term schema refers to the architecture of the
database which describes how it will appear or will be constructed. It describes the organization of
data such as tables, relationships as well as constraints. A schema is a template that dictates how
data items in a database will be stored, arranged, and accessed.
Schema is of three types: Logical Schema, Physical Schema and view Schema.
• View Schema – It defines the design of the database at the view level.
Example:
Let’s say a table teacher in our database named school, the teacher table requires the name, dob,
and doj in their table so we design a structure as:
Teacher table
name: String
doj: date
dob: date
Advantages of Schema
• Consistency: Guarantees proper storage of data in order to allow easy access and
expandability.
• Structure: Helps in easy arrangement of the data base in an organized manner and hence
makes it easy to comprehend.
• Data Integrity: Puts in place restrictions that ensure the data’s maintaining of its accuracy
and subsequent reliability.
Disadvantages of Schema
• Rigidity: Schemas, defined, may be rigid for alteration, and may take a huge amount of effort
in order to alter the scheme.
What is Instance?
An instance of DBMS refers to real data in a database coming at some particular point in time.
Instance on the other hand refers to the content in the database in as much as it refers to the
structure defined under a particular schema at a given point.
Example
Let’s say a table teacher in our database whose name is School, suppose the table has 50 records so
the instance of the database has 50 records for now and tomorrow we are going to add another fifty
records so tomorrow the instance has a total of 100 records. This is called an instance.
Advantages of Instance
• Real-Time Representation: It a return of the data in the database at a certain point in time
as may be required for analysis or for performing operations.
• Flexibility: While a schema remains fixed in time, instances can be quite volatile, as data is
written, updated, or deleted.
Disadvantages of Instance
• Volatility: Those are occurrences may be dynamic in a way they are different over time and
this may make it a challenge to keep track without the necessary intervention.
• Data Integrity Issues: If not well regulated, it is evident that the data in an instance could
become very inconsistent and at times even incorrect.
Affects the entire database structure. Affects only the current state of data.
Requires significant effort and planning to Easily altered by performing CRUD (Create,
change. Read, Update, Delete) operations.
Data independence:-
Data independence is a property of a database management system by which we can change the
database schema at one level of the database system without changing the database schema at the
next higher level. In this article, we will learn in full detail about data independence and will also see
its types. If you read it completely, you will understand it easily.
In the context of a database management system, data independence is the feature that allows the
schema of one layer of the database system to be changed without any impact on the schema of the
next higher level of the database system. ” Through data independence, we can build an
environment in which data is independent of all programs, and through the three schema
architectures, data independence will be more understandable. Data via two card stencils along with
centralized DBMS data is a form of transparency that has value for someone.
It can be summed up as a sort of immunity of user applications that adjusts correctly and does not
change addresses, imparting the class of data and their order. I want the separate applications not to
be forced to deal with data representation and storage specifics because this decreases quality and
flexibility. DBMS permits you to see data with such a generalized sight. It actually means that the
ability to change the structure of the lower-level schema without presenting the upper-level schema
is called data independence.
Types of Data Independence
• Changing the logical schema (conceptual level) without changing the external schema (view
level) is called logical data independence.
• It is used to keep the external schema separate from the logical schema.
• If we make any changes at the conceptual level of data, it does not affect the view level.
• For example, it is possible to add or delete new entities, attributes to the conceptual schema
without making any changes to the external schema.
• Making changes to the physical schema without changing the logical schema is called
physical data independence.
• If we change the storage size of the database system server, it will not affect the conceptual
structure of the database.
• It is used to keep the conceptual level separate from the internal level.
It mainly concerns how the data is stored in It mainly concerns about changes to the
the system. structure or data definition.
It tells about the internal schema. It tells about the conceptual schema.
There may or may not be a need for changes Whenever the logical structure of
to be made at the internal level to improve the database has to be changed, the changes
the structure. made at the logical level are important.
What is a Database?
A Database Management System (DBMS) is the software that interacts with the database, providing
an interface to users and applications. It ensures the efficient storage and retrieval of data, maintains
data integrity, and provides security features like access control and authentication.
Database languages are specialized languages used to interact with a database. They allow users to
perform different tasks such as defining, controlling, and manipulating the data. There are several
types of database languages in DBMS, categorized into the following four main types:
Each category serves a different purpose within the database management process. Let's break down
each one.
• ALTER: Used to modify the structure of an existing database object, such as adding a new
column to a table.
• TRUNCATE: Used to remove all rows from a table, without affecting the structure.
Now we will explain each command with examples for better understanding of the concepts.
CREATE Command
The CREATE is a DDL command used to create databases, tables, triggers and other database objects.
Syntax
Example:
Alter Command
ALTER is a DDL command which changes or modifies the existing structure of the database, and it
also changes the schema of database objects. We can also add and drop constraints of the table
using the ALTER command.
Syntax
Example:
Drop Command
DROP is a DDL command used to delete/remove the database objects from the SQL database. We
can easily remove the entire table, view, or index from the database using this DDL command.
Syntax
Example:
Truncate Command
The TRUNCATE command is used to delete all the records from a table without removing the
structure. Unlike the DELETE command, which can remove specific rows and can be rolled
back, TRUNCATE is a more efficient way to delete all rows in a table without logging individual row
deletions.
Syntax
Example:
Rename Command
The RENAME command in a Database Management System (DBMS) is used to change the name of a
database object, such as a table, column, or index. This command is helpful when we want to give a
more meaningful or appropriate name to an object without needing to recreate it.
Syntax:
DCL stands for Data Control Language. It is used to control the access permissions of users to the
database. DCL commands help grant or revoke privileges to users, determining who can perform
actions like reading or modifying data. DCL commands are transactional, meaning they can be rolled
back if necessary.
Now we will explain these commands with proper examples for better understanding
Grant Command
Syntax
GRANT privileges
ON object
TO user_or_role [WITH GRANT OPTION];
Example:
Revoke Command
The REVOKE command in a Database Management System (DBMS) is used to remove previously
granted permissions or privileges from users or roles. This command is essential for managing access
control, ensuring that users do not have more privileges than necessary to perform their tasks.
Syntax
Example
The DML (Data Manipulation Language) is used toto manage and manipulate data within a database.
With DML, you can perform various operations such as inserting, updating, selecting, and deleting
data. These operations allow you to work with the actual content in your database tables.
• MERGE: Performs an "upsert" operation, which means updating existing records or inserting
new ones if they don’t exist.
• LOCK TABLE: Prevents other users from accessing the table while changes are being made.
Now, we will explain these commands with examples for better understanding:
SELECT Command
The SELECT command in SQL (Structured Query Language) is used to retrieve data from one or more
tables in a database. It is the most commonly used commands in SQL, allowing users to specify which
columns and rows of data they want to retrieve and how they want that data organized.
The SELECT statement can be used in various ways, such as selecting all data from a table, filtering
records based on conditions, or sorting the results.
Syntax
Insert Command
The INSERT command in SQL (Structured Query Language) is used to add new records or rows to a
table in a database. It is a key operation in database management, essential for populating tables
with new data. This command can insert data into all columns or specific columns of a table.
Syntax
INSERT INTO Table_Name (Column 1, Column 2, Column 3, Column 4) VALUES (Value 1, Value 2,Value
3, Value 4);
Update Command
The UPDATE command in SQL (Structured Query Language) is used to modify existing records in a
table. This command enables users to change the values of one or more columns for specific rows
based on a condition (criteria). It is crucial for maintaining and adjusting data in a database when
necessary.
Syntax
Example:
Delete Command
The DELETE command in SQL (Structured Query Language) is used to remove one or more existing
records from a table in a database. It is an essential operation for managing data, enabling users to
delete specific rows that meet certain conditions or criteria.
Syntax:
Example:
Merge Command
The Merge command in SQL is used to perform an upsert operation, which combines
both UPDATE and INSERT actions. It allows you to insert new rows if they do not exist, or update
existing rows if they match a certain condition. This command is particularly useful for synchronizing
two tables by inserting new records and updating existing ones in a single operation.
Syntax:
MERGE INTO target_table AS target
USING source_table AS source
ON (target.id = source.id)
WHEN MATCHED THEN
UPDATE SET target.name = source.name
WHEN NOT MATCHED THEN
INSERT (id, name) VALUES (source.id, source.name);
Example:
Employee Table
New_Hires Table
Output
CALL Command
The Call command is used to invoke a stored procedure or user-defined function, which is a set of
precompiled SQL statements. It allows you to execute complex operations within a database as a
single unit.
Syntax:
Example:
LOCK TABLE
The lock table command is used to lock the table for preventing access from others, ensuring no
other operations (like insertions, updates, or deletions) can be performed on the table while it's
locked. Useful for transactional operations where consistency is important.
Syntax:
Example:
The TCL full form is Transaction Control Language commands are used to manage and control
transactions in a database, grouping them into logical units. These commands help ensure the
integrity of data and consistency during complex operations. Here are the two main commands in
this category:
• Commit: Saves all the changes made during the current transaction to the database. These
are very useful in the banking sector.
• Rollback: used to restore the database to its original state from the last commit. This
command also plays an important role in Banking Sectors.
Now we will explain these two commands for better understanding with examples
Commit Command
The COMMIT command is used to save all changes made during a transaction in the database. This
command ensures that modifications made by DML statements (such as INSERT, UPDATE, or DELETE)
become permanent in the database.
Syntax
Database Operation
Commit
Example:
ROLLBACK Command
The rollback command is used to restore the database to its state at the last COMMIT, effectively
undoing any changes made since that point. It helps ensure data consistency by allowing the reversal
of partial or erroneous operations.
Syntax
ROLLBACK;
Example:
Conclusion
In conclusion, database languages play a crucial role in managing and manipulating data in a
database management system (DBMS). There are different type of database language
like DDL, DCL, DML, and TCL. The DDL language is used for used for defining the database's internal
structure and Pattern of the Database. The DCL commands are used to control the data from the user
means They can provide control of the Database, Table, and Data. The DML commands are used to
manipulate the Data in the Table like Inserting, updating, and deleting the Data finally the TCL
commands are used to save and restore the previous state of the Database.
In this article, We will learn about the DDL Full Form by understanding various examples and so on.
What is DDL?
DDL actually represents Data Definition Language, which is actually a set of commands used to
create a structure and maintain databases. Those would
include CREATE, ALTER, DROP, TRUNCATE, and RENAME statements for creating, changing the
structure of, and dropping structures in the database, such as tables. DDL basically deals with the
storage of the data and not the data itself.
Example: The ‘CREATE TABLE’ command defines a new table called “Employees” with columns
including EmployeeID, FirstName, LastName, and HireDate along with their datatypes.
FirstName VARCHAR(50),
LastName VARCHAR(50),
HireDate DATE
);
• CREATE
• ALTER
• DROP
• TRUNCATE
• RENAME
1. CREATE
Syntax:
column_name1 datatype1,
column_name2 datatype2,
column_name3 datatype3,
column_name4 datatype4
);
The column_name in create table command will tell the name of the column and corresponding
datatype will specify the datatype of that column. Here in this table the three column_names namely
– Student_id is of type int, Name is of type varchar and Marks is of type int.
for example:
CREATE TABLE
Student
(Student_id INT,
Name VARCHAR(100),
Marks INT);
2. ALTER
Alter command is used for altering the table in many forms like:
1. Add a column
3. Drop a column
column_name datatype);
The above command will add a new column to the table.And the resulting table will have one more
column like this:
ADD
(Address VARCHAR(200));
Here this command will add a new column “Address” in the table Student of datatype varchar(200);
ALTER TABLE
table_name
RENAME
old_column_name TO new_column_name;
The above command will rename the existing column to new column.
ALTER TABLE
Student
RENAME
Marks TO Age;
The command above will change the column_name from Marks to Age;
ALTER TABLE
table_name
DROp
(column_name);
DROP
(Age);
ALTER TABLE
Student MODIFY
(column_name datatype);
ALTER TABLE
Student
MODIFY
(name varchar(300));
The above command will modify the column_name “Name” by changing the size of that column.
3. TRUNCATE
This command removes all the records from a table. But this command will not destroy the table’s
structure.
Syntax :
This will delete all the records from the table. For example the below command will remove all the
records from table student.
Example:
4. DROP
This command completely removes the table from the database along with the destruction of the
table structure.
Syntax –
This will delete all the records as well as the structure of the table.
This is the main difference between TRUNCATE AND DROP.-TRUNCATE only removes the records
whereas DROP completely destroys the table.
Example:
This command will remove the table records as well as destroys the schema too.
This is all about the DDL commands.
Advantages of DDL
• Defines Structure: DDL commands like CREATE and ALTER allow you to set up and modify the
structure of database objects (tables, indexes, views), organizing data effectively.
• Manages Schema: You can easily create, update, or remove entire database schemas,
making it simpler to maintain and update the database structure over time.
• Enforces Data Integrity: DDL allows the implementation of rules and constraints (PRIMARY
KEY, FOREIGN KEY, UNIQUE, NOT NULL) that ensure data remains accurate and consistent.
• Boosts Performance: By creating indexes and partitions using DDL commands, you can
significantly improve query performance and speed up data retrieval.
• Standardized: DDL commands are standardized across most SQL-based databases, making it
easier to apply knowledge across different database systems.
Disadvantages of DDL
• Irreversible Changes: DDL commands, especially DROP and TRUNCATE, are auto-committed,
meaning changes can’t be undone once executed. This can result in permanent data loss if
not used carefully.
• Risk of Data Loss: Misuse of commands like DROP can delete entire tables along with their
data, leading to significant data loss, particularly if no backup is available.
• Complex for Large Databases: Altering the structure of large databases can be complicated
and may require downtime or additional planning to avoid disrupting operations.
• Causes Locking: DDL operations can lock database objects during execution, which might
slow down or block other operations, impacting overall database performance.
• Compatibility Issues: While DDL is standardized, different databases (like MySQL, Oracle, or
PostgreSQL) may have variations in syntax and features, leading to compatibility issues
during migration.
Applications of DDL
• Creating Database Objects: DDL statements can be used to create various database objects
such as tables, views, indexes, and stored procedures.
• Modifying Database Objects: DDL statements can be used to modify the structure of existing
database objects such as adding or dropping columns from tables, modifying the data type
of columns, renaming tables or columns, etc.
• Managing Database Constraints: DDL statements can be used to create or alter database
constraints such as primary keys, foreign keys, unique constraints, and check constraints.
• Indexing: DDL statements can be used to create or modify indexes on database tables, which
can improve the performance of SQL queries.
• Partitioning: DDL statements can be used to create or modify partitioned tables, which can
improve the performance of queries that access large amounts of data.
Overall, DDL is an essential part of SQL and is used extensively in database management systems to
create, modify and manage database objects.
DML:-
DML stands for Data Manipulation Language. Tables and formulas are helpful when communicating
with data stored up to a point in a database through SQL (Structured Query Language), but a time
comes when we actually want to execute some fairly complicated data interactions. We will also
need the Data Manipulation Language in that situation. DML is a way to inform a database precisely
what we want it to do by conversing in a manner that it has been built to comprehend from scratch.
When it comes to interacting with existing data, whether adding, moving, or deleting data, it
provides a convenient way to do so.
Transaction control is required for the DML statements. Any modification that a DML statement
makes to the database will be called a transaction. Any adjustment made by the DML statement
must, therefore, be controlled by TCL statements (Transaction Control Language). DML is a subset of
SQL statements that alter the information stored in tables. As, it mainly concentrates on database
performance, as well as it utilizes HDFS (Hadoop Distributed File System) storage’s append-only
nature.
There are basically two types of Data Manipulation Language. These are mentioned below. We have
described them in the difference between format.
It can be used on its own for precisely specifying It must be integrated to a general-
complex operations in the database. purpose programming language.
It demands that a user must clearly state which data is It demands that a user must clearly
needed without clarifying how and when to obtain state which data is needed and how to
those data. obtain those data.
High-Level or Non-Procedural DML Low-level or Procedural DML
For Example: Every SQL statement is a prescriptive For Example: DB2’s SQL PL,
command. Oracle’s PL/SQL.
Characteristics of DML
It performs interpret-only data queries. It is used in a database schema to recall and manipulate the
information. DML It is a dialect which is used to select, insert, delete and update data in a database.
Data Manipulation Language (DML) commands are as follows:
SELECT Command
This command is used to get data out of the database. It helps users of the database to access from
an operating system, the significant data they need. It sends a track result set from one tables or
more.
Syntax :
SELECT *
FROM <table_name>;
Example:
SELECT *
FROM students;
OR
SELECT *
FROM students
INSERT Command
This command is used to enter the information or values into a row. We can connect one or more
records to a single table within a repository using this instruction. This is often used to connect an
unused tag to the documents.
Syntax:
Example :
UPDATE Command
This command is used to alter existing table records. Within a table, it modifies data from one or
more records. This command is used to alter the data which is already present in a table.
Syntax:
UPDATE <table_name>
WHERE condition;
Example:
UPDATE students
DELETE Command
It deletes all archives from a table. This command is used to erase some or all of the previous table’s
records. If we do not specify the ‘WHERE’ condition then all the rows would be erased or deleted.
Syntax:
WHERE <condition>;
Example:
Advantages of DML
• DML statements could alter the data that is contained or stored in the database.
• DML aims to have many different varieties and functionalities between vendors providing
databases.
Disadvantages of DML
• Access the data without having the data stored in the object.
DML statements allow you to query, edit, add, and remove data stored in database objects. The
primary DML commands are SELECT, INSERT, DELETE, and UPDATE. Using DML statements, you can
perform powerful actions on the actual data stored in your system. You’ll typically see DML SELECT
statements written in data models to conduct data analysis or create new tables and views. In many
ways, DML is the air that us data folks breathe.
In a Database Management System (DBMS), the overall structure of a database typically consists of
several layers and components that work together to store, manage, and retrieve data efficiently.
Here's an outline of the key components and structure:
• Definition: The schema is the logical view of the entire database, specifying how the data is
organized and how the relationships between the data are structured.
• Types of Schemas:
o External Schema: User views of the database (e.g., different user interfaces or access
levels).
o Conceptual Schema: Represents the logical view of the entire database, abstracted
from physical details (i.e., a unified structure of all data).
o Internal Schema: Describes the physical storage of the data, how the data is stored
on disk (e.g., indexing, file organization).
2. Tables (Relations)
• Definition: A table is the most fundamental structure where data is stored. Each table is
composed of rows and columns.
3. Indexes
• Definition: Indexes are special data structures that improve the speed of data retrieval
operations by providing a faster way to look up data in a table.
• Usage: Indexing is typically used to improve performance in SELECT queries, although they
can slow down write operations (INSERT, UPDATE, DELETE).
4. Primary Keys
• Definition: A primary key is a unique identifier for a row in a table. Each table typically has
one primary key, which uniquely identifies each record in that table.
• Uniqueness: The primary key ensures that no two rows have the same value for the key
attribute(s).
5. Foreign Keys
• Definition: A foreign key is a column or set of columns in a table that establishes a link
between data in two tables. It refers to the primary key in another table.
• Usage: Used to enforce referential integrity between tables, ensuring consistency in the
relationships between records.
6. Relationships
• One-to-One (1:1): Each record in the first table is related to one and only one record in the
second table.
• One-to-Many (1:N): A single record in the first table can be related to multiple records in the
second table.
• Many-to-Many (M:N): Multiple records in one table can be related to multiple records in
another table (often implemented using a junction table).
7. Views
• Definition: A view is a virtual table that represents the result of a query. It doesn't store data
itself but presents a specific subset of data from one or more tables.
• Usage: Useful for creating customized user views, aggregating data, or simplifying complex
queries.
8. Transactions
• ACID Properties:
o Atomicity: All operations in a transaction are either fully completed or fully rolled
back.
o Isolation: Transactions are isolated from each other, ensuring that concurrent
transactions do not interfere with each other.
o Durability: Once a transaction is committed, its changes are permanent even in case
of a system failure.
9. Normalization
• Definition: The process of organizing data to reduce redundancy and improve data integrity.
It involves breaking a database into smaller tables and ensuring that relationships between
data are consistent.
• Forms: There are several levels of normalization (1NF, 2NF, 3NF, BCNF) to avoid anomalies in
data insertion, deletion, and updates.
• Triggers: Special types of stored procedures that automatically execute in response to certain
events on a table (e.g., INSERT, UPDATE, DELETE).
• Backup: Regular snapshots of the database are taken to ensure that data can be recovered in
case of failure.
• Recovery: Methods to restore the database to a consistent state after a crash, based on logs
and backup data.
• Definition: A repository that contains metadata about the database, such as table
definitions, columns, data types, indexes, and constraints.
• Usage: Used by the DBMS to manage the structure and integrity of the database.
• Tables:
• Indexes: Index on BookID for faster book lookup, and on CustomerID for faster customer
search.
• Views: A view might combine information from Books, Orders, and OrderDetails to show a
summary of orders placed by a customer.
• Stored Procedures: A procedure to calculate total sales for a specific time period.
This is just a general overview. The actual DBMS structure will depend on the type of DBMS
(relational, NoSQL, etc.) and the complexity of the application it supports.
Transaction Management :-
Transactions are a set of operations used to perform a logical set of work. A transaction usually
means that the data in the database has changed. One of the major uses of DBMS is to protect the
user data from system failures. It is done by ensuring that all the data is restored to a consistent state
when the computer is restarted after a crash. The transaction is any one execution of the user
program in a DBMS. One of the important properties of the transaction is that it contains a finite
number of steps. Executing the same program multiple times will generate multiple transactions.
1. Transaction Start.
9. Transaction Completed.
• Write/Change data (W): Write the data item from the memory variable to the disk.
• Commit: Commit is a transaction control language that is used to permanently save the
changes done in a transaction
Example: Transfer of 50₹ from Account A to Account B. Initially A= 500₹, B= 800₹. This data is
brought to RAM from Hard Disk.
For a transaction to be performed in DBMS, it must possess several properties often called ACID
properties.
• A – Atomicity
• C – Consistency
• I – Isolation
• D – Durability
Transaction States
Transactions can be implemented using SQL queries and Servers. In the diagram, you can see
how transaction states work.
For a transaction to be performed in DBMS, it must possess several properties often called ACID
properties.
• A – Atomicity
• C – Consistency
• I – Isolation
• D – Durability
Transaction States
Transactions can be implemented using SQL queries and Servers. In the diagram, you can see
how transaction states work.
The transaction has four properties. These are used to maintain consistency in a database, before
and after the transaction.
Property of Transaction:
• Atomicity
• Consistency
• Isolation
• Durability
Atomicity
• States that all operations of the transaction take place at once if not, the transactions are
aborted.
• There is no midway, i.e., the transaction cannot occur partially. Each transaction is treated as
one unit and either run to completion or is not executed at all.
• Abort: If a transaction stops or fails, none of the changes it made will be saved or visible.
• Commit: If a transaction completes successfully, all the changes it made will be saved and
visible.
Consistency
• The rules (integrity constraint) that keep the database accurate and consistent are followed
before and after a transaction.
• When a transaction is completed, it leaves the database either as it was before or in a new
stable state.
• This property means every transaction works with a reliable and consistent version of the
database.
• The transaction is used to transform the database from one consistent state to another
consistent state. A transaction changes the database from one consistent state to another
consistent state.
Isolation
• It shows that the data which is used at the time of execution of a transaction cannot be used
by the second transaction until the first one is completed.
• In isolation, if the transaction T1 is being executed and using the data item X, then that data
item can’t be accessed by any other transaction T2 until the transaction T1ends.
• The concurrency control subsystem of the DBMS enforced the isolation property
Durability
• The durability property is used to indicate the performance of the database’s consistent
state. It states that the transaction made the permanent changes.
• They cannot be lost by the erroneous operation of a faulty transaction or by the system
failure. When a transaction is completed, then the database reaches a state known as the
consistent state. That consistent state cannot be lost, even in the event of a system’s failure.
• The recovery subsystem of the DBMS has the responsibility of Durability property.
The recovery-management component of a database system can support atomicity and durability by
a variety of schemes. E.g. the shadow-database scheme:
Shadow copy
• In the shadow-copy scheme, a transaction that wants to update the database first creates a
complete copy of the database.
• All updates are done on the new database copy, leaving the original copy, the shadow copy,
untouched. If at any point the transaction has to be aborted, the system merely deletes the
new copy. The old copy of the database has not been affected.
• This scheme is based on making copies of the database, called shadow copies, assumes that
only one transaction is active at a time.
• The scheme also assumes that the database is simply a file on disk. A pointer called db
pointer is maintained on disk, It points to the current copy of the database.
Some other transaction may also have used value produced by the failed transaction. So we also
have to rollback those transactions. The SQL standard defines four isolation levels:
• Read Uncommitted: Read Uncommitted is the lowest isolation level. In this level, one
transaction may read not yet committed changes made by other transaction, there by
allowing dirty reads. In this level, transactions are not isolated from each other.
• Read Committed: This isolation level guarantees that any data read is committed at the
moment it is read. Thus it does not allows dirty read. The transaction holds a read or write
lock on the current row, and thus prevent other transactions from reading, updating or
deleting it.
• Repeatable Read: This is the most restrictive isolation level. The transaction holds locks on
all rows it references and writes locks on all rows it inserts, updates, deletes. Since other
transaction cannot read, update or delete these rows, consequently it
avoids non-repeatable read.
Failure Classification
To find that where the problem has occurred, we generalize a failure into the following categories:
• Transaction failure
• System crash
• Disk failure
1. Transaction failure
The transaction failure occurs when it fails to execute or when it reaches a point from where it can’t
go any further. If a few transactions or process is hurt, then this is called as transaction failure.
2. Syntax error: It occurs where the DBMS itself terminates an active transaction because the
database system is not able to execute it. For example, The system aborts an active
transaction, in case of deadlock or resource unavailability.
2. System Crash
System failure can occur due to power failure or other hardware or software failure. Example:
Operating system error.
3. Disk Failure
• It occurs where hard-disk drives or storage drives used to fail frequently. It was a common
problem in the early days of technology evolution.
• Disk failure occurs due to the formation of bad sectors, disk head crash, and unreachability
to the disk or any other failure, which destroy all or part of disk storage.
Serializability
It is an important aspect of Transactions. In simple meaning, you can say that serializability is a way
to check whether two transactions working on a database are maintaining database consistency or
not.
It is of two types:
1. Conflict Serializability
2. View Serializability
Schedule
Schedule, as the name suggests is a process of lining the transactions and executing them one by
one. When there are multiple transactions that are running in a concurrent manner and the order of
operation is needed to be set so that the operations do not overlap each other, Scheduling is brought
into play and the transactions are timed accordingly.
It is of two types:
1. Serial Schedule
2. Non-Serial Schedule
• The DBMS is used to schedule the access of data concurrently. It means that the user can
access multiple data from the database without being interfered with by each other.
Transactions are used to manage concurrency.
• Transaction Management is also used forConcurrency Control Protocols and the Locking of
data.
• Makes certain that updates to the database don’t affect its dependability or accuracy.
• It may be difficult to change the information within the transaction database by end-users.
• We need to always roll back and start from the beginning rather than continue from the
previous state.
Database users are categorized based on their interaction with the database. There are seven types
of database users in DBMS. Below mentioned are the types of database users:
A Database Administrator (DBA) is a person/team who defines the schema and also controls the 3
levels of the database. The DBA will then create a new account ID and password for the user if
he/she needs to access the database. DBA is also responsible for providing security to the database
and he allows only authorized users to access/modify the database. DBA is responsible for problems
such as security breaches and poor system response time.
• DBA also monitors the recovery and backup and provides technical support.
• The DBA has a DBA account in the DBMS which is called a system or superuser account.
• DBA is the one having privileges to perform DCL (Data Control Language) operations such
as GRANT and REVOKE, to allow/restrict a particular user from accessing the database.
Parametric End Users are the unsophisticated who don’t have any DBMS knowledge but they
frequently use the database applications in their daily life to get the desired results. For example,
Railway’s ticket booking users are naive users. Clerks in any bank is a naive user because they don’t
have any DBMS knowledge but they still use the database and perform their given task.
3. A System Analyst
A system Analyst is a user who analyzes the requirements of parametric end users. They check
whether all the requirements of end users are satisfied.
4. Sophisticated Users
Sophisticated users can be engineers, scientists, business analyst, who are familiar with the database.
They can develop their own database applications according to their requirement. They don’t write
the program code but they interact the database by writing SQL queries directly through the query
processor.
5. Database Designers
Data Base Designers are the users who design the structure of database which includes tables,
indexes, views, triggers, stored procedures and constraints which are usually enforced before the
database is created or populated with data. He/she controls what data must be stored and how the
data items to be related. It is the responsibility of Database Designers to understand the
requirements of different user groups and then create a design which satisfies the need of all the
user groups.
6. Application Programmers
Application Programmers also referred as System Analysts or simply Software Engineers, are the
back-end programmers who writes the code for the application programs. They are the computer
professionals. These programs could be written in Programming languages such as Visual Basic,
Developer, C, FORTRAN, COBOL etc. Application programmers design, debug, test, and maintain set
of programs called “canned transactions” for the Naive (parametric) users in order to interact with
database.
Casual Users are the users who occasionally use/access the database but each time when they
access the database they require the new information, for example, Middle or higher level manager.
8. Specialized users
Specialized users are sophisticated users who write specialized database application that does not fit
into the traditional data-processing framework. Among these applications are computer aided-
design systems, knowledge-base and expert systems etc.