0% found this document useful (0 votes)
5 views

Database

A Database Management System (DBMS) is software that manages databases, allowing users to create, manipulate, and secure data while providing an interface for various operations. DBMS offers advantages such as reduced redundancy, data sharing, and easy maintenance, but also has disadvantages like high costs and complexity. Users of DBMS are categorized into different types, including Database Administrators, naive users, and application programmers, each with specific roles and responsibilities in managing and utilizing the database.

Uploaded by

raghavrk3032
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Database

A Database Management System (DBMS) is software that manages databases, allowing users to create, manipulate, and secure data while providing an interface for various operations. DBMS offers advantages such as reduced redundancy, data sharing, and easy maintenance, but also has disadvantages like high costs and complexity. Users of DBMS are categorized into different types, including Database Administrators, naive users, and application programmers, each with specific roles and responsibilities in managing and utilizing the database.

Uploaded by

raghavrk3032
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Database Management System : Database management system is a software which is used to Structure of DBMS : DBMS means Database Management

ase Management System, which is a tool or software


manage the database. For example: MySQL, Oracle, etc are a very popular commercial database used to create the database or delete or manipulate the database. A software programme
which is used in different applications.DBMS provides an interface to perform various created to store, retrieve, query, and manage data is known as a Database Management System
operations like database creation, storing data in it, updating data, creating a table in the (DBMS). Data can be generated, read, updated, and destroyed by authorized entities thanks to
database and a lot more.It provides protection and security to the database. In the case of user interfaces (UIs).Because they give programmers, Database Managers, and end users a
multiple users, it also maintains data consistency. consolidated view of the data, Database Management Systems are crucial because they relieve
applications and end users of the need to comprehend the physical location of the data.
Characteristics of DBMS : It uses a digital repository established on a server to store and Application Programme Interfaces (APIs) manage internet requests and responses for particular
manage the information.It can provide a clear and logical view of the process that manipulates sorts of data.In marketing materials, the phrase "database as a service" (DBaaS) may be used to
data.DBMS contains automatic backup and recovery procedures.It contains ACID properties refer to both relational and non-relational DBMS components that are given via the internet.
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.

Different types of Database Users : Database users are categorized based up on their
interaction with the database. These are seven types of database users in DBMS.

Database Administrator (DBA) : Database Administrator (DBA) is a person/team who defines


the schema and also controls the 3 levels of database. The DBA will then create a new account
id and password for the user if he/she need to access the database. DBA is also responsible for Three Parts that make up the Database System are: The explanations for these are provided
providing security to the database and he allows only the authorized users to access/modify the below:
data base. DBA is responsible for the problems such as security breaches and poor system
response time.DBA also monitors the recovery and backup and provide technical support.The 1. Query Processor : The query processing is handled by the query processor, as the name
DBA has a DBA account in the DBMS which called a system or superuser account.DBA repairs implies. It executes the user's query, to put it simply. In this way, the query processor aids the
damage caused due to hardware and/or software failures.DBA is the one having privileges to database system in making data access simple and easy. The query processor's primary duty is
perform DCL (Data Control Language) operations such as GRANT and REVOKE, to allow/restrict a to successfully execute the query. The Query Processor transforms (or interprets) the user's
particular user from accessing the database. application program-provided requests into instructions that a computer can understand.

Naive / Parametric End Users : Parametric End Users are the unsophisticated who don’t have Components of the Query Processor : DDL Interpreter : Data Definition Language is what DDL
any DBMS knowledge but they frequently use the database applications in their daily life to get stands for. As implied by the name, the DDL Interpreter interprets DDL statements like those
the desired results. For examples, Railway’s ticket booking users are naive users. Clerks in any used in schema definitions (such as create, remove, etc.). This interpretation yields a set of
bank is a naive user because they don’t have any DBMS knowledge but they still use the tables that include the meta-data (data of data) that is kept in the data dictionary. Metadata
database and perform their given task. may be stored in a data dictionary. In essence, it is a part of the disc storage that will be covered
in a later section of this article.
System Analyst :System Analyst is a user who analyzes the requirements of parametric end
users. They check whether all the requirements of end users are satisfied. Sophisticated Users : DML Compiler:Compiler for DML Data Manipulation Language is what DML stands for. In
Sophisticated users can be engineers, scientists, business analyst, who are familiar with the keeping with its name, the DML Compiler converts DML statements like select, update, and
database. They can develop their own database applications according to their requirement. delete into low-level instructions or simply machine-readable object code, to enable execution.
They don’t write the program code but they interact the database by writing SQL queries The optimization of queries is another function of the DML compiler. Since a single question can
directly through the query processor. typically be translated into a number of evaluation plans. As a result, some optimization is
needed to select the evaluation plan with the lowest cost out of all the options. This process,
Database Designers : Data Base Designers are the users who design the structure of database known as query optimization, is exclusively carried out by the DML compiler. Simply put, query
which includes tables, indexes, views, triggers, stored procedures and constraints which are optimization determines the most effective technique to carry out a query.
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 responsibility of Database Embedded DML Pre-compiler : Before the query evaluation, the embedded DML commands in
Designers to understand the requirements of different user groups and then create a design the application program (such as SELECT, FROM, etc., in SQL) must be pre-compiled into
which satisfies the need of all the user groups. standard procedural calls (program instructions that the host language can understand).
Therefore, the DML statements which are embedded in an application program must be
Application Programmers : Application Programmers also referred as System Analysts or simply converted into routine calls by the Embedded DML Pre-compiler.
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 Query Optimizer:It starts by taking the evaluation plan for the question, runs it, and then
Programming languages such as Visual Basic, Developer, C, FORTRAN, COBOL etc. Application returns the result. Simply said, the query evaluation engine evaluates the SQL commands used
programmers design, debug, test, and maintain set of programs called “canned transactions” for to access the database's contents before returning the result of the query. In a nutshell, it is in
the Naive (parametric) users in order to interact with database. charge of analyzing the queries and running the object code that the DML Compiler produces.
Apache Drill, Presto, and other Query Evaluation Engines are a few examples.
Casual Users / Temporary Users : 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 2. Storage Manager:An application called Storage Manager acts as a conduit between the
example, Middle or higher level manager. queries made and the data kept in the database. Another name for it is Database Control
System. By applying the restrictions and running the DCL instructions, it keeps the database's
Specialized users : Specialized users are sophisticated users who write specialized database consistency and integrity. It is in charge of retrieving, storing, updating, and removing data from
application that does not fit into the traditional data-processing framework. Among these the database.
applications are computer aided-design systems, knowledge-base and expert systems etc.
Components of Storage Manager : Following are the components of Storage Manager: Integrity 1. Data Definition Language(DDL):It is used to construct a database. DDL implements database
Manager:Whenever there is any change in the database, the Integrity manager will manage the schema at the physical, logical, and external levels. The following commands serve as the base
integrity constraints. Authorization Manager : Authorization manager verifies the user that he is for all DDL commands:
valid and authenticated for the specific query or request. File Manager : All the files and data
structure of the database are managed by this component. Transaction Manager : It is ALTER<object>
responsible for making the database consistent before and after the transactions. Concurrent
processes are generally controlled by this component. Buffer Manager : The transfer of data
COMMENT
between primary and main memory and managing the cache memory is done by the buffer
manager.
CREATE<object>
3. Disk Storage : A DBMS can use various kinds of Data Structures as a part of physical system
implementation in the form of disk storage. DESCRIBE<object>

Components of Disk Storage : Following are the components of Disk Manager: Data Dictionary : DROP<object>
It contains the metadata (data of data), which means each object of the database has some
information about its structure. So, it creates a repository which contains the details about the SHOW<object>
structure of the database object.Data Files : This component stores the data in the files.Indices :
These indices are used to access and retrieve the data in a very fast and efficient way.
USE<object>

Disadvantages of Traditional File System : Data redundancy and inconsistency.Difficulty in


2. Data Manipulation Language(DML): It is used to access a database. The DML provides the
accessing data.Data isolation – multiple files and formats.Integrity problems. Unauthorized
statements to retrieve, modify, insert and delete the data from the database. The following
access is not restricted.It co-ordinates only physical access.
commands serve as the base for all DML commands:

Components of DBMS : There are many components available in the DBMS. Each component
INSERT
has a significant task in the DBMS. A database environment is a collection of components that
regulates the use of data, management, and a group of data. These components consist of
people, the technique of Handel the database, data, hardware, software, etc. there are several UPDATE
components available for the DBMS. We are going to explain five main topics of the database
below. DELETE

Hardware : Here the hardware means the physical part of the DBMS. Here the hardware LOCK
includes output devices like a printer, monitor, etc., and storage devices like a hard disk.In DBMS,
information hardware is the most important visible part. The equipment which is used for the
CALL
visibility of the data is the printer, computer, scanner, etc. This equipment is used to capture the
data and present the output to the user.With the help of hardware, the DBMS can access and
update the database. EXPLAIN PLAN

Software : Software is the main component of the DBMS.Software is defined as the collection of People : The people who control and manage the databases and perform different types of
programs that are used to instruct the computer about its work. The software consists of a set operations on the database in the DBMS.The people include database administrator, software
of procedures, programs, and routines associated with the computer system's operation and developer, and End-user.Database administrator-database administrator is the one who
performance. Also, we can say that computer software is a set of instructions that is used to manages the complete database management system. DBA takes care of the security of the
instruct the computer hardware for the operation of the computers. DBMS, its availability, managing the license keys, managing user accounts and access,
etc.Software developer- theThis user group is involved in developing and designing the parts of
DBMS. Native Users,Online Users,Sophisticated Users,Specialized Users,Application Users, DBA
Data : The term data means the collection of any raw fact stored in the database. Here the data
- Database Administrator
are any type of raw material from which meaningful information is generated.The database can
store any form of data, such as structural data, non-structural data, and logical data.The
structured data are highly specific in the database and have a structured format. 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
Procedures : The procedure is a type of general instruction or guidelines for the use of DBMS.
PCs and a workstation which are connected via the network.DBMS architecture depends upon
This instruction includes how to set up the database, how to install the database, how to log in
how users are connected to the database to get their request done.
and log out of the database, how to manage the database, how to take a backup of the
database, and how to generate the report of the database.In DBMS, with the help of procedure,
we can validate the data, control the access and reduce the traffic between the server and the Types of DBMS Architecture :
clients.

CREATE [OR REPLACE] PROCEDURE procedure_name (<Argument> {IN, OUT, IN OUT}

<Datatype>,...)

IS

Declaration section<variable, constant> ;

BEGIN
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.
Execution section

1-Tier Architecture : In this architecture, the database is directly available to the user. It means
EXCEPTION
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
Exception section used for development of the local application, where programmers can directly communicate
with the database for the quick response.
END
2-Tier Architecture : The 2-Tier architecture is same as basic client-server. In the two-tier
Database Access Language : Database Access Language is a simple language that allows users to architecture, applications on the client end can directly communicate with the database at the
write commands to perform the desired operations on the data that is stored in the server side. For this interaction, API's like: ODBC, JDBC are used. The user interfaces and
database.Database Access Language is a language used to write commands to access, upsert, application programs are run on the client-side. The server side is responsible to provide the
and delete data stored in a database.Users can write commands or query the database using functionalities like: query processing and transaction management.
Database Access Language before submitting them to the database for execution.
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.

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
3-Tier Architecture : The 3-Tier architecture contains another layer between the client and insert data into a table. Update: It is used to update existing data within a table. Delete: It is
server. In this architecture, client can't directly communicate with the server.The application on used to delete all records from a table. Merge: It performs UPSERT operation, i.e., insert or
the client-end interacts with an application server which further communicates with the update operations.Call: It is used to call a structured query language or a Java subprogram.
database system.End user has no idea about the existence of the database beyond the Explain Plan: It has the parameter of explaining data. Lock Table: It controls concurrency.
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.
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.

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.

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.

Difference between Schema & Instance :


There are two types of data independence : Logical Data Independence : Logical data
independence refers characteristic of being able to change the conceptual schema without
Database Schema Database Instance
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,
It is the definition of the database, or it is It is a snapshot of a database at a specific then the user view of the data would not be affected.Logical data independence occurs at the
defined as the description of the database. moment. user interface level.

It rarely changes. It changes frequently. 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
This corresponds to the variable declaration The value of the variable in a program at a changes in the storage size of the database system server, then the Conceptual structure of the
of a programming language. point in time corresponds to an instance of database will not be affected.Physical data independence is used to separate conceptual levels
the database schema. from the internal levels.Physical data independence occurs at the logical interface level.

Defines the basic structure of the database, It is the set of Information stored at a
i.e., how the data will be stored in the particular time.
database.

Schema is same for whole database. Data in instances can be changed using
addition, deletion, updation.

It does not change very frequently. It changes very frequently.

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 :

Data Models : 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.

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.
3.Entity-relationship Model : In this database model, relationships are created by dividing
object of interest into entity and its characteristics into attributes.Let's take an example, If we
have to design a School Database, then Student will be an entity with attributes name, age,
address etc. As Address is generally complex, it can be another entity with attributes street
name, pincode, city etc.
4.Relational Model : In this model, data is organised in two-dimensional tables and the
relationship is maintained by storing a common field.This model was introduced by E.F Codd in
1970, and since then it has been the most widely used database model, infact, we can say the
only database model used around the world.The basic structure of data in the relational model
is tables.

Advantages of Data Models : Data Models help us in representing data accurately. It helps us in
1. Strong Entity : A Strong Entity is a type of entity that has a key
finding the missing data and also in minimizing Data Redundancy.Data Model provides data
Attribute. Strong Entity does not depend on other Entity in the Schema. It has a primary key,
security in a better way.The data model should be detailed enough to be used for building the
that helps in identifying it uniquely, and it is represented by a rectangle. These are called Strong
physical database.
Entity Types.

Disadvantages of Data Models : In the case of a vast database, sometimes it becomes difficult
2. Weak Entity : An Entity type has a key attribute that uniquely identifies each entity in the
to understand the data model.You must have the proper knowledge of SQL to use physical
entity set. But some entity type exists for which key attributes can’t be defined. These are
models.Even smaller change made in structure require modification in the entire application.
called Weak Entity types. For Example, A company may store the information of dependents
(Parents, Children, Spouse) of an Employee. But the dependents don’t have existed without the
Introduction of ER Model : The Entity Relational Model is a model for identifying entities to be employee.
represented in the database and representation of how those entities are related. The ER data
model specifies enterprise schema that represents the overall logical structure of a database
graphically. The Entity Relationship Diagram explains the relationship among the entities
present in the database.

Symbols Used in ER Model :

Attributes : Attributes are the properties that define the entity type. For example, Roll_No,
Name, DOB, Age, Address, and Mobile_No are the attributes that define entity type Student. In
ER diagram, the attribute is represented by an oval.

Components of ER Diagram : ER Model consists of Entities, Attributes, and Relationships among 1. Key Attribute : The attribute which uniquely identifies each entity in the entity set is called
Entities in a Database System. the key attribute. For example, Roll_No will be unique for each student. In ER diagram, the key
attribute is represented by an oval with underlying lines.

2. Composite Attribute : An attribute composed of many other attributes is called a composite


attribute. For example, the Address attribute of the student Entity type consists of Street, City,
State, and Country. In ER diagram, the composite attribute is represented by an oval comprising
of ovals.

Entity : An Entity may be an object with a physical existence – a particular person, car, house, or
employee – or it may be an object with a conceptual existence – a company, a job, or a
university course.

Entity Set: An Entity is an object of Entity Type and a set of all entities is called an entity set. For
Example, E1 is an entity having Entity Type Student and the set of all students is called Entity Set.
In ER diagram, Entity Type is represented as:

3. Multivalued Attribute : An attribute consisting of more than one value for a given entity. For
example, Phone_No (can be more than one for a given student). In ER diagram, a multivalued
attribute is represented by a double oval.
2. Binary Relationship: When there are TWO entities set participating in a relationship, the
4. Derived Attribute : An attribute that can be derived from other attributes of the entity type is relationship is called a binary relationship. For example, a Student is enrolled in a Course.
known as a derived attribute. e.g.; Age (can be derived from DOB). In ER diagram, the derived

attribute is represented by a dashed oval. 3. n-ary Relationship: When there are n entities set participating in a relation, the relationship is
called an n-ary relationship.

The Complete Entity Type Student with its Attributes can be represented as:
Cardinality : The number of times an entity of an entity set participates in a relationship set is
known as cardinality. Cardinality can be of different types:

1. One-to-One: When each entity in each entity set can take part only once in the relationship,
the cardinality is one-to-one. Let us assume that a male can marry one female and a female can
marry one male. So the relationship will be one-to-one. the total number of tables that can be
used in this is 2.

Relationship Type and Relationship Set : A Relationship Type represents the association
Using Sets, it can be represented as:
between entity types. For example, ‘Enrolled in’ is a relationship type that exists between entity
type Student and Course. In ER diagram, the relationship type is represented by a diamond and
connecting the entities with lines.

A set of relationships of the same type is known as a relationship set. The following relationship
set depicts S1 as enrolled in C2, S2 as enrolled in C1, and S3 as registered in C3.

2. One-to-Many: In one-to-many mapping as well where each entity can be related to more
than one relationship and the total number of tables that can be used in this is 2. Let us assume
that one surgeon deparment can accomodate many doctors. So the Cardinality will be 1 to M. It
means one deparment has many Doctors.total number of tables that can used is 3.

Degree of a Relationship Set : The number of different entity sets participating in a relationship
set is called the degree of a relationship set.

1. Unary Relationship: When there is only ONE entity set participating in a relation, the
relationship is called a unary relationship. For example, one person is married to only one
person.

Usi
ng sets, one-to-many cardinality can be represented as:
3. Many-to-One: When entities in one entity set can take part only once in the relationship set
and entities in other entity sets can take part more than once in the relationship set, cardinality
is many to one. Let us assume that a student can take only one course but one course can be
taken by many students. So the cardinality will be n to 1. It means that for one course there can
be n students but for one student, there will be only one course. The total number of tables that
can be used in this is 3.

G
eneralization : 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.

Using Sets, it can be represented as:

Specialization : Specialization is a top-down approach, and it is opposite to Generalization. In


In this case, each student is taking only 1 course but 1 course has been taken by many students.
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
4. Many-to-Many: When entities in all entity sets can take part more than once in the distinguishing characteristics.Normally, the superclass is defined first, the subclass and its
relationship cardinality is many to many. Let us assume that a student can take more than one related attributes are defined next, and relationship set are then added. For example: In an
course and one course can be taken by many students. So the relationship will be many to Employee management system, EMPLOYEE entity can be specialized as TESTER or DEVELOPER
many. the total number of tables that can be used in this is 3. based on what role they play in the company.

Usin
g Sets, it can be represented as:

Aggregation : 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 12 Codd's Rules : Every database has tables, and constraints cannot be referred to as a rational
in a relationship with another entity visitor. In the real world, if a visitor visits a coaching center database system. And if any database has only relational data model, it cannot be a Relational
then he will never enquiry about the Course only or just about the Center instead he will ask the Database System (RDBMS). So, some rules define a database to be the correct RDBMS. These
enquiry about both. rules were developed by Dr. Edgar F. Codd (E.F. Codd) in 1985,

Rule 0: The Foundation Rule : The database must be in relational form. So that the system can
handle the database through its relational capabilities.

Rule 1: Information Rule : A database contains various information, and this information must
be stored in each cell of a table in the form of rows and columns.

Rule 2: Guaranteed Access Rule : Every single or precise data (atomic value) may be accessed
logically from a relational database using the combination of primary key value, table name, and
column name.

Rule 3: Systematic Treatment of Null Values : This rule defines the systematic treatment of Null
values in database records. The null value has various meanings in the database, like missing the
data, no value in a cell, inappropriate information, unknown data and the primary key should
not be null.
What is
RDBMS : RDBMS stands for Relational Database Management Systems. It is basically a program
Rule 4: Active/Dynamic Online Catalog based on the relational model : It represents the entire
that allows us to create, delete, and update a relational database. A Relational Database is a
logical structure of the descriptive database that must be stored online and is known as a
database system that stores and retrieves data in a tabular format organized in the form of rows database dictionary. It authorizes users to access the database and implement a similar query
and columns. It is a smaller subset of DBMS which was designed by E.F Codd in the 1970s. The
language to access the database.
major DBMSs like SQL, My-SQL, and ORACLE are all based on the principles of relational DBMS.

Rule 5: Comprehensive Data SubLanguage Rule : The relational database supports various
RDBMS-Full-Form : Relational DBMS owes its foundation to the fact that the values of each
languages, and if we want to access the database, the language must be the explicit, linear or
table are related to others. It has the capability to handle larger magnitudes of data and
well-defined syntax, character strings and supports the comprehensive: data definition, view
simulate queries easily.
definition, data manipulation, integrity constraints, and limit transaction management
operations. If the database allows access to the data without any language, it is considered a
Relational Database Management Systems maintains data integrity by simulating the violation of the database.
following features: Entity Integrity: No two records of the database table can be completely
duplicate.Referential Integrity: Only the rows of those tables can be deleted which are not used
Rule 6: View Updating Rule : All views table can be theoretically updated and must be
by other tables. Otherwise, it may lead to data inconsistency.User-defined Integrity: Rules
practically updated by the database systems.
defined by the users based on confidentiality and access.Domain integrity: The columns of the
database tables are enclosed within some structured limits, based on default values, type of
data or ranges. Rule 7: Relational Level Operation (High-Level Insert, Update and delete) Rule : A database
system should follow high-level relational operations such as insert, update, and delete in each
level or a single row. It also supports union, intersection and minus operation in the database
Characteristics of RDBMS : Data must be stored in tabular form in DB file, that is, it should be
system.
organized in the form of rows and columns.Each row of table is called record/tuple . Collection
of such records is known as the cardinality of the tableEach column of the table is called an
attribute/field. Collection of such columns is called the arity of the table.No two records of the Rule 8: Physical Data Independence Rule : All stored data in a database or an application must
DB table can be same. Data duplicity is therefore avoided by using a candidate key. Candidate be physically independent to access the database. Each data should not depend on other data
Key is a minimum set of attributes required to identify each record uniquely. or an application. If data is updated or the physical structure of the database is changed, it will
not show any effect on external applications that are accessing the data from the database.

Relational Database Model : The relational database paradigm, created by IBM’s E.F. Codd in
the 1970s, enables any table to be associated to another table by means of a common attribute. Rule 9: Logical Data Independence Rule : It is similar to physical data independence. It means, if
Codd suggested a change to a data model where data is stored, accessed, and related in tables any changes occurred to the logical level (table structures), it should not affect the user's view
without restructuring the tables that hold them in place of hierarchical structures. Each (application). For example, suppose a table either split into two tables, or two table joins to
spreadsheet in the relational database model is a table that contains data, which is shown as create a single table, these changes should not be impacted on the user view application.
rows (records or tuples) and columns (attributes).
Rule 10: Integrity Independence Rule : A database must maintain integrity independence when
Example: The following table STUDENT consists of three columns Roll Number, Name, Section inserting data into table's cells using the SQL query language. All entered values should not be
and four records of students 1, 2, 3 and 4 respectively. The records can’t be completely same, changed or rely on any external factor or application to maintain integrity. It is also helpful in
the Roll Number acts as a candidate key which separates records. making the database-independent for each front-end application.

Roll number Name Section Rule 11: Distribution Independence Rule : The distribution independence rule represents a
database that must work properly, even if it is stored in different locations and used by different
end-users. Suppose a user accesses the database through an application; in that case, they
1 Ishita A
should not be aware that another user uses particular data, and the data they always get is only
located on one site.
2 Yash B
Rule 12: Non Subversion Rule :The non-submersion rule defines RDBMS as a SQL language to
3 Ishita A store and manipulate the data in the database. If a system has a low-level or separate language
other than SQL to access the database system, it should not subvert or bypass integrity to
4 Mallika C transform data.

Advantages of RDBMS : Easy to manage: Each table can be independently manipulated without SQL Commands : SQL commands are instructions. It is used to communicate with the database.
affecting others.Security: It is more secure consisting of multiple levels of security. Access of It is also used to perform specific tasks, functions, and queries of data.SQL can perform various
data shared can be limited.Flexible: Updating of data can be done at a single point without tasks like create a table, add data to tables, drop the table, modify the table, set permission for
making amendments at multiple files. Databases can easily be extended to incorporate more users.Types of SQL Commands. There are five types of SQL commands: DDL, DML, DCL, TCL, and
records, thus providing greater scalability. Also, facilitates easy application of SQL queries.Users: DQL.
RDBMS supports client-side architecture storing multiple users together. Facilitates storage and
retrieval of large amount of data.

Disadvantages of RDBMS : High Cost and Extensive Hardware and Software Support: Huge costs
and setups are required to make these systems functional.Scalability: In case of addition of more
data, servers along with additional power, and memory are required.Complexity: Voluminous
data creates complexity in understanding of relations and may lower down the performance.
For example : INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");

b. UPDATE: This command is used to update or modify the value of a column in the table.

Syntax : UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE


CONDITION]

For example : UPDATE students

SET User_Name = 'Sonoo'

WHERE Student_Id = '3'

c. DELETE: It is used to remove one or more row from a table.

Syntax : DELETE FROM table_name [WHERE condition];

1. Data Definition Language (DDL) : DDL changes the structure of the table like creating a table, For example : DELETE FROM javatpoint
deleting a table, altering a table, etc.All the command of DDL are auto-committed that means it
permanently save all the changes in the database.Here are some commands that come under WHERE Author="Sonoo";
DDL:
3. Data Control Language : DCL commands are used to grant and take back authority from any
a. CREATE : It is used to create a new table in the database. database user.Here are some commands that come under DCL:

Syntax : CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]); a. Grant: It is used to give user access privileges to a database.

Example : CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB DATE); Example : GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;

b. DROP: It is used to delete both the structure and record stored in the table. b. Revoke: It is used to take back permissions from the user.

Syntax : DROP TABLE table_name; Example : REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;

Example : DROP TABLE EMPLOYEE; 4. Transaction Control Language : TCL commands can only use with DML commands like INSERT,
DELETE and UPDATE only.These operations are automatically committed in the database that's
c. ALTER: It is used to alter the structure of the database. This change could be either to modify why they cannot be used while creating tables or dropping them.
the characteristics of an existing attribute or probably to add a new attribute.
a. Commit: Commit command is used to save all the transactions to the database.
Syntax : To add a new column in the table
Syntax : COMMIT;
ALTER TABLE table_name ADD column_name COLUMN-definition;
Example : DELETE FROM CUSTOMERS
To modify existing column in the table:
WHERE AGE = 25;
ALTER TABLE table_name MODIFY(column_definitions....);
COMMIT;
EXAMPLE :
b. Rollback: Rollback command is used to undo transactions that have not already been saved
ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20)); to the database.

ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20)); Syntax : ROLLBACK;

d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the Example : DELETE FROM CUSTOMERS
table.
WHERE AGE = 25;
Syntax : TRUNCATE TABLE table_name;
ROLLBACK;
Example : TRUNCATE TABLE EMPLOYEE;
c. SAVEPOINT: It is used to roll the transaction back to a certain point without rolling back the
2. Data Manipulation Language : DML commands are used to modify the database. It is entire transaction.
responsible for all form of changes in the database.The command of DML is not auto-committed
that means it can't permanently save all the changes in the database. They can be rollback.Here Syntax : SAVEPOINT SAVEPOINT_NAME;
are some commands that come under DML:
5. Data Query Language : DQL is used to fetch the data from the database. It uses only one
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table. command:

Syntax: INSERT INTO TABLE_NAME a. SELECT: This is the same as the projection operation of relational algebra. It is used to select
the attribute based on the condition described by WHERE clause.
(col1, col2, col3,.... col N)
Syntax : SELECT expressions
VALUES (value1, value2, value3, .... valueN);
FROM TABLES
Or : INSERT INTO TABLE_NAME
WHERE conditions;
VALUES (value1, value2, value3, .... valueN);
For example : SELECT emp_name contains Fixed-length non-unicode characters.

FROM employee varchar It has a maximum length of 8000 characters. It


contains variable-length non-unicode
WHERE age > 20; characters.

SQL Datatype : SQL Datatype is used to define the values that a column can contain. Every text It has a maximum length of 2,147,483,647
column is required to have a name and data type in the database table. characters. It contains variable-length non-
unicode characters.
Datatype of SQL:

5. Date and time Datatypes : The subtypes are given below:

Datatype Description

Data It is used to store the year, month, and days


value.

time It is used to store the hour, minute, and


second values.
1. Binary Datatypes : There are Three types of binary Datatypes which are given below:
timestamp It stores the year, month, day, hour, minute,
Data Type Description and the second value.

binary It has a maximum length of 8000 bytes. It


contains fixed-length binary data.
Types Of operators In DBMS :
varbinary It has a maximum length of 8000 bytes. It
contains variable-length binary data. Arithmetic Operators : We can use various arithmetic operators on the data stored in the tables.
Arithmetic Operators are:
image It has a maximum length of 2,147,483,647
bytes. It contains variable-length binary data. Operator Description

+ The addition is used to perform an addition operation on the


data values.
2. Approximate Numeric Datatype : The subtypes are given below:
- This operator is used for the subtraction of the data values.
Data type From To Description
/ This operator works with the ‘ALL’ keyword and it calculates
float -1.79E + 308 1.79E + 308 It is used to specify a division operations.
floating-point value
e.g. 6.2, 2.9 etc. * This operator is used for multiplying data values.

real -3.40e + 38 3.40E + 38 It specifies a single % Modulus is used to get the remainder when data is divided by
precision floating point another.
number.

Example Query : SELECT * FROM employee WHERE emp_city NOT LIKE 'A%';
3. Exact Numeric Datatype : The subtypes are given below:

Output:
Data type Description

int It is used to specify an integer value.

smallint It is used to specify small integer value.

bit It has the number of bits to store.

decimal It specifies a numeric value that can have a


decimal number.
Comparison Operators : Another important operator in SQL is a comparison operator, which is
used to compare one expression’s value to other expressions. SQL supports different types of
numeric It is used to specify a numeric value. comparison operator, which is described below:

Operator Description

4. Character String Datatype : The subtypes are given below: = Equal To

Data type Description > Greater Than

char It has a maximum length of 8000 characters. It < Less Than


>= Greater Than Equal To 4 Angel 55000 10 Technical

<= Less Than Equal To

<> Not Equal To 5 Will 20000 30 Finance

Example Query : SELECT * FROM MATHS WHERE MARKS=50; IN operator : The IN operator is true if the query results in values that are contained in the list of
constant values for the IN operator. For example −
Output:
Select * from Employee

Where Emp_ID IN (1,2,5);

This query gives details about the employees whose Employee number is 1,2 or 5 i.e Aaron,
Harry and Will.

Emp_ID Emp_Name Emp_Salary Emp_DeptID Emp_DeptName

1 Aaron 10000 10 Technical

2 Harry 12000 20 Operations

5 Will 20000 30 Finance

Logical Operators : The Logical operators are those that are true or false. They return true or
false values to combine one or more true or false values.

LIKE operator : The LIKE operator is used to select the values that match the patterns specified
operator Description
in the query. Two wildcard operators are used for this. For example −

AND Logical AND compares two Booleans as


Select * from Employee
expressions and returns true when both
expressions are true.
Where Emp_Name LIKE “A%”

OR Logical OR compares two Booleans as


expressions and returns true when one of the This query returns the data of all the employees whose name starts with A i.e. Aaron and Angel
in our example.
expressions is true.

Emp_ID Emp_Name Emp_Salary Emp_DeptID Emp_DeptName


Not Not takes a single Boolean as an argument
and change its value from false to true or from
true to false.
1 Aaron 10000 10 Technical

4 Angel 55000 10 Technical


Example Query : SELECT * FROM employee WHERE emp_city =

'Allahabad' AND emp_country = 'India';


Conversion Function in SQL : When you define expressions and local variables then you should
Output: specify what type of data will be stored in those objects such as text data, money, dates,
numbers, or characters.Strings Data types such as CHAR and VARCHAR.Decimal values such as
FLOAT and REAL. Binary String such as BINARY.Date and Time Data Types such as DATE, TIME,
TIMESTAMP, and DATETIME.Numeric Data types such as INT, DOUBLE, and BIGINT. MS Access
Data Types such as TEXT, LONG, and BYTE.On the basis of this, there are two types of conversion
in the Data first implicit types conversion and the second is explicit data type conversion.

Implicit Data Type Conversion : A VARCHAR2 or CHAR value can be implicitly converted to
NUMBER or DATE type value by Oracle. Similarly, a NUMBER or DATA type value can be
automatically converted to character data by Oracle server. Note that the impicit
interconversion happens only when the character represents the a valid number or date type
value respectively. For example, examine the below SELECT queries. Both the queries will give
Special Operators : the same result because Oracle internally treats 15000 and '15000' as same.

BETWEEN operator : The BETWEEN operator returns the information within a given range of Query-1
values, where the minimum and maximum of the range is specified. For example − Select * from
Employee
SELECT employee_id,first_name,salary

Where Emp_Salary BETWEEN 20000 AND 60000;


FROM employees

This query returns information about all the employees whose salary is between the range of
WHERE salary > 15000;
20000 and 60000 i.e. Angel and Will in this case.

Query-2
Emp_id Emp_Name Emp_Salary Emp_DeptID Emp_deptName

SELECT employee_id,first_name,salary
FROM employees Where : σ is used for selection prediction r is used for relation

WHERE salary > '15000'; p is used as a propositional logic formula which may use connectors like: AND OR and NOT.
These relational can use as relational operators like =, ≠, ≥, <, >, ≤.
Explicit Data Type Conversion : SQL Conversion functions are single row functions which are
capable of typecasting column value, literal or an expression . TO_CHAR, TO_NUMBER and For example: LOAN Relation
TO_DATE are the three functions which perform cross modification of data types.
BRANCH_NAME LOAN_NO AMOUNT
TO_CHAR function
Downtown L-17 1000
TO_CHAR function is used to typecast a numeric or date input to character type with a format
model (optional).
Redwood L-23 2000

Syntax : TO_CHAR(number1, [format], [nls_parameter])


Perryride L-15 1500

Consider the below SELECT query. The query format the HIRE_DATE and SALARY columns of
Downtown L-14 1500
EMPLOYEES table using TO_CHAR function.

SELECT first_name, Mianus L-13 500

TO_CHAR (hire_date, 'MONTH DD, YYYY') HIRE_DATE, Roundhill L-11 900

TO_CHAR (salary, '$99999.99') Salary Perryride L-16 1300

FROM employees

WHERE rownum < 5; Input : σ BRANCH_NAME="perryride" (LOAN)

FIRST_NAME HIRE_DATE SALARY Output :

-------------------- ------------------ ---------- BRANCH_NAME LOAN_NO AMOUNT

Steven JUNE 17, 2003 $24000.00 Perryride L-15 1500

Neena SEPTEMBER 21, 2005 $17000.00 Perryride L-16 1300

Lex JANUARY 13, 2001 $17000.00

Alexander JANUARY 03, 2006 $9000.00 2. Project Operation : This operation shows the list of those attributes that we wish to appear in
the result. Rest of the attributes are eliminated from the table. It is denoted by ∏. Notation: ∏
The first TO_CHAR is used to convert the hire date to the date format MONTH DD, YYYY i.e. A1, A2, An (r) Where A1, A2, A3 is used as an attribute name of relation r.
month spelled out and padded with spaces, followed by the two-digit day of the month, and
then the four-digit year. Example: CUSTOMER RELATION

TO_DATE function : The function takes character values as input and returns formatted date NAME STREET CITY
equivalent of the same. The TO_DATE function allows users to enter a date in any format, and
then it converts the entry into the default format used by Oracle 11g.
Jones Main Harrison

Syntax : TO_DATE( string1, [ format_mask ], [ nls_language ] )


Smith North Rye

A format_mask argument consists of a series of elements representing exactly what the data
should look like and must be entered in single quotation marks. Hays Main Harrison

Relational Algebra : Relational algebra is a procedural query language. It gives a step by step Curry North Rye
process to obtain the result of the query. It uses operators to perform queries.
Johnson Alma Brooklyn

Brooks Senator Brooklyn


Types of Relational operation

Input : ∏ NAME, CITY (CUSTOMER)

Output :

NAME CITY

Jones Harrison

Smith Rye

1. Hays Harrison
Select Operation : The select operation selects tuples that satisfy a given predicate.It is denoted
by sigma (σ). Notation: σ p(r)
Curry Rye Jackson

Johnson Brooklyn Curry

Brooks Brooklyn Williams

Mayes

3. Union Operation : Suppose there are two tuples R and S. The union operation contains all the
tuples that are either in R or S or both in R & S. It eliminates the duplicate tuples. It is denoted
by ∪. Notation: R ∪ S A union operation must hold the following condition: R and S must have 4. Set Intersection : Suppose there are two tuples R and S. The set intersection operation
the attribute of the same number. Duplicate tuples are eliminated automatically.
contains all tuples that are in both R & S. It is denoted by intersection ∩. Notation: R ∩ S
Example: Using the above DEPOSITOR table and BORROW table
Example : DEPOSITOR RELATION
Input : ∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME (DEPOSITOR)
CUSTOMER_NAME ACCOUNT_NO
Output :
Johnson A-101
CUSTOMER_NAME
Smith A-121
Smith
Mayes A-321
Jones
Turner A-176

Johnson A-273
5. Set Difference : Suppose there are two tuples R and S. The set intersection operation contains
Jones A-472 all tuples that are in R but not in S.It is denoted by intersection minus (-). Notation: R - S
Example: Using the above DEPOSITOR table and BORROW table

Lindsay A-284
Input : ∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME (DEPOSITOR)

Output :

BORROW RELATION :
CUSTOMER_NAME

CUSTOMER_NAME LOAN_NO
Jackson

Jones L-17
Hayes

Smith L-23
Willians

Hayes L-15
Curry

Jackson L-14
6. Cartesian product : The Cartesian product is used to combine each row in one table with each
row in the other table. It is also known as a cross product.It is denoted by X.Notation: E X D
Curry L-93
Example : EMPLOYEE

Smith L-11
EMP_ID EMP_NAME EMP_DEPT

Williams L-17
1 Smith A

2 Harry C

Input : ∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR)


3 John B

Output :

CUSTOMER_NAME
DEPARTMENT :

Johnson
DEPT_NO DEPT_NAME

Smith
A Marketing

Hayes
B Sales

Turner
C Legal

Jones

Lindsay
Input : EMPLOYEE X DEPARTMENT
Output : A. INNER JOIN : The INNER JOIN keyword selects all rows from both the tables as long as the
condition is satisfied. This keyword will create the result-set by combining all rows from both the
tables where the condition satisfies i.e value of the common field will be the same.
EMP_ID EMP_NAME EMP_DEPT DEPT_NO DEPT_NAME

Syntax : SELECT table1.column1,table1.column2,table2.column1,....


1 Smith A A Marketing

FROM table1
1 Smith A B Sales

INNER JOIN table2


1 Smith A C Legal

ON table1.matching_column = table2.matching_column;
2 Harry C A Marketing

table1: First table.


2 Harry C B Sales

table2: Second table


2 Harry C C Legal

matching_column: Column common to both the tables.


3 John B A Marketing

Note: We can also write JOIN instead of INNER JOIN. JOIN is same as INNER JOIN.
3 John B B Sales

3 John B C Legal

7. Rename Operation : The rename operation is used to rename the output relation. It is
denoted by rho (ρ). Example: We can use the rename operator to rename STUDENT relation to
STUDENT1. ρ(STUDENT1, STUDENT)

SQL Join statement is used to combine data or rows from two or more tables based on a
common field between them.
Example Queries(INNER JOIN) : This query will show the names and age of students enrolled in
different courses.
Consider the two tables below as follows : Student
SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE FROM Student

INNER JOIN StudentCourse

ON Student.ROLL_NO = StudentCourse.ROLL_NO;

Output:

StudentCourse :

Join (Cartesian Join & Self Join) : Consider the two tables below:

StudentCourse :

The simplest Join is INNER JOIN.


Example Queries(SELF JOIN) : SELECT a.ROLL_NO , b.NAME

FROM Student a, Student b

WHERE a.ROLL_NO < b.ROLL_NO;

Output :

CARTESIAN JOIN: The CARTESIAN JOIN is also known as CROSS JOIN. In a CARTESIAN JOIN there
is a join for each row of one table to every row of another table. This usually happens when the
matching column or WHERE condition is not specified.In the absence of a WHERE condition the
CARTESIAN JOIN will behave like a CARTESIAN PRODUCT . i.e., the number of rows in the result-
set is the product of the number of rows of the two tables.In the presence of WHERE condition
this JOIN will function like a INNER JOIN.Generally speaking, Cross join is similar to an inner join
where the join-condition will always evaluate to True

Syntax : SELECT table1.column1 , table1.column2, table2.column1...

FROM table1 EQUI Join and NON EQUI JOIN : Example –Let’s Consider the two tables given below.

CROSS JOIN table2; Table name — Student

table1: First table. In this table, you have I’d, name, class and city are the fields.

table2: Second table Select * from Student;

Example Queries(CARTESIAN JOIN) : In the below query we will select NAME and Age from id name class city
Student table and COURSE_ID from StudentCourse table. In the output you can see that each
row of the table Student is joined with every row of the table StudentCourse. The total rows in 3 Hina 3 Delhi
the result-set = 4 * 4 = 16.

4 Megha 2 Delhi
SELECT Student.NAME, Student.AGE, StudentCourse.COURSE_ID

6 Gouri 2 Delhi
FROM Student

CROSS JOIN StudentCourse;

Table name — Record : In this table, you have I’d, class and city are the fields.
Output:

Select * from Record;

id class city

9 3 Delhi

10 2 Delhi

12 2 Delhi

EQUI JOIN : EQUI JOIN creates a JOIN for equality or matching column(s) values of the relative
tables. EQUI JOIN also create JOIN by using JOIN with ON and then providing the names of the
columns with their relative tables to check equality using equal sign (=).

Syntax : SELECT column_list

FROM table1, table2....

SELF JOIN : As the name signifies, in SELF JOIN a table is joined to itself. That is, each row of the WHERE table1.column_name =
table is joined with itself and all other rows depending on some conditions. In other words we
can say that it is a join between two copies of the same table.Syntax: table2.column_name;

SELECT a.coulmn1 , b.column2 Example –

FROM table_name a, table_name b SELECT student.name, student.id, record.class, record.city

WHERE some_condition; FROM student, record

table_name: Name of the table. WHERE student.city = record.city;

some_condition: Condition for selecting the rows. Or


Syntax : SELECT column_list Megha 12 Delhi

FROM table1 Gouri 12 Delhi

JOIN table2

[ON (join_condition)] lossless join decomposition : Lossless-join decomposition is a process in which a relation is
decomposed into two or more relations. This property guarantees that the extra or less tuple
Example – SELECT student.name, student.id, record.class, record.city generation problem does not occur and no information is lost from the original relation during
the decomposition. It is also known as non-additive join decomposition.When the sub relations
combine again then the new relation must be the same as the original relation was before
FROM student
decomposition.

JOIN record
R = (A, B, C), R1 = (A, B), R2 = (B, C)

ON student.city = record.city;
The relation R has three attributes A, B, and C. The relation R is decomposed into two relation
R1 and R2. . R1 and R2 both have 2-2 attributes.The common attributes are B.The Value in
Output : Column B must be unique. if it contains a duplicate value then the Lossless-join decomposition is
not possible.
name id class city
Draw a table of Relation R with Raw Data − R (A, B, C)
Hina 3 3 Delhi
A B C
Megha 4 3 Delhi
12 25 34
Gouri 6 3 Delhi
10 36 09
Hina 3 2 Delhi
12 42 30
Megha 4 2 Delhi

Gouri 6 2 Delhi
It decomposes into the two sub relations − R1 (A, B)
Hina 3 2 Delhi
A B
Megha 4 2 Delhi
12 25
Gouri 6 2 Delhi
10 36

12 42
NON EQUI JOIN : NON EQUI JOIN performs a JOIN using comparison operator other than
equal(=) sign like >, <, >=, <= with conditions. Syntax : SELECT *

FROM table_name1, table_name2 R2 (B, C)

WHERE table_name1.column [> | < | >= | <= ] table_name2.column; B C

Example – SELECT student.name, record.id, record.city


25 34

FROM student, record


36 09

WHERE Student.id < Record.id ;


42 30

Output :

name Id City
Now, we can check the first condition for Lossless-join decomposition.The union of sub relation
R1 and R2 is the same as relation R. R1U R2 = R
Hina 9 Delhi

We get the following result −


Megha 9 Delhi

A B C
Gouri 9 Delhi

12 25 34
Hina 10 Delhi
10 36 09
Megha 10 Delhi
12 42 30
Gouri 10 Delhi

Hina 12 Delhi
The relation is the same as the original relation R. Hence, the above decomposition is Lossless-
join decomposition.
Views in SQL : Views in SQL are considered as a virtual table. A view also contains rows and Object Views : This indirectly updates the Employees table.In summary, relational views in a
columns.To create the view, we can select the fields from one or more tables present in the DBMS provide a way to present data in a structured manner without altering the original tables.
database.A view can either have specific rows based on certain condition or all the rows of a They enhance security, simplify complex queries, and allow for a more intuitive data
table. presentation for users.Let me provide a detailed explanation with an example:

Advantages of View: Complexity: Views help to reduce the complexity. Different views can be 1.User-Defined Types (UDTs): Object views often involve user-defined types, where users can
created on the same base table for different users.Security: It increases the security by define their own data types to represent complex structures or objects.
excluding the sensitive information from the view. Data Integrity: If data is accessed and
entered through a view, the DBMS can automatically check the data to ensure that it meets the 2.Attributes and Methods: UDTs can have attributes (fields) and methods (functions) associated
specified integrity constraints.Storage Capacity: Views take very little space to store the with them, making them more versatile than traditional data types.
data.Logical Data Independence: View can make the application and database tables to a
certain extent independent.
3.Creating Object Types : CREATE TYPE AddressType AS OBJECT (

Disadvantages of View : The DML statements which can be performed on a view created using
street VARCHAR2(50),
single base table have certain restrictions are: You cannot INSERT if the base table has any not
null column that do not appear in view.You cannot INSERT or UPDATE if any of the column
referenced in the INSERT or UPDATE contains group functions or columns defined by expression. city VARCHAR2(50),

Types Of Views : Relational Views : In a relational database management system (DBMS), a zip_code VARCHAR2(10)
relational view is a virtual table derived from one or more base tables through a query. Views
allow users to access and manipulate data stored in the underlying tables without directly );
altering them. Here's a detailed explanation with an example:

4.Creating Tables with Object Types : CREATE TABLE Employee (


1. Creating a Base Table : Let's say we have a base table named Employees:

emp_id NUMBER PRIMARY KEY,


CREATE TABLE Employees (

emp_name VARCHAR2(100),
EmployeeID INT PRIMARY KEY,

emp_address AddressType
FirstName VARCHAR(50),

);
LastName VARCHAR(50),

5.Inserting Data : INSERT INTO Employee VALUES (


Department VARCHAR(50)

1,
);

'John Doe',
2. Populating the Base Table : INSERT INTO Employees VALUES

AddressType('123 Main St', 'Cityville', '12345')


(1, 'John', 'Doe', 'IT'),

);
(2, 'Jane', 'Smith', 'HR'),

6.Object Views : CREATE VIEW EmployeeView AS


(3, 'Bob', 'Johnson', 'Finance');

SELECT emp_id, emp_name, emp_address.street AS street,


3. Creating a Relational View : Now, let's create a view named IT_Employees that shows
employees in the IT department:
emp_address.city AS city, emp_address.zip_code AS zip_code

CREATE VIEW IT_Employees AS


FROM Employee;

SELECT EmployeeID, FirstName, LastName


7.Querying Object View : SELECT * FROM EmployeeView WHERE city = 'Cityville'; This allows
users to query the data in a more intuitive way, accessing attributes of the object directly.
FROM Employees

Benefits of Object Views : Abstraction: Object views abstract the underlying complexity of the
WHERE Department = 'IT'; data structure, making it easier for users to interact with. Encapsulation: Users can encapsulate
complex data structures within object types, promoting a more modular and organized database
This view doesn't store data itself but dynamically retrieves it from the base table based on the design.Readability: Object views enhance the readability of queries by providing a clear
defined query. structure for accessing object attributes.

4. Querying the View : Users can query the view like they would a regular table: SQL | Subquery : In SQL a Subquery can be simply defined as a query within another query. In
other words we can say that a Subquery is a query that is embedded in WHERE clause of
another SQL query. Important rules for Subqueries : You can place the Subquery in a number of
SELECT * FROM IT_Employees;
SQL clauses: WHERE clause, HAVING clause, FROM clause. Subqueries can be used with SELECT,
UPDATE, INSERT, DELETE statements along with expression operator. It could be equality
The result would be a subset of the Employees table containing only IT department employees. operator or comparison operator such as =, >, =, <= and Like operator. A subquery is a query
within another query.
5. Updating Through a View : Views can also be used to update the underlying data. For
example, changing the department of an employee through the view: Syntax: There is not any general syntax for Subqueries. However, Subqueries are seen to be
used most frequently with SELECT statement as shown below:
UPDATE IT_Employees
SELECT column_name
SET Department = 'Development'
FROM table_name
WHERE EmployeeID = 1;
WHERE column_name expression operator
( SELECT COLUMN_NAME from TABLE_NAME WHERE ... ); SQL INDEX : The Index in SQL is a special table used to speed up the searching of the data in the
database tables. It also retrieves a vast amount of data from the tables frequently. The INDEX
Types Of Subqueries : Subqueries in SQL are queries that are nested within another query. They requires its own space in the hard disk.The index concept in SQL is same as the index concept in
can be classified into various types based on their usage. Here are some common types of the novel or a book.It is the best SQL technique for improving the performance of queries.
subqueries with examples:
Why SQL Index : The following reasons tell why Index is necessary in SQL : SQL Indexes can
Single-Row Subquery : Retrieves a single value (one row, one column). search the information of the large database quickly. This concept is a quick process for those
columns, including different values. This data structure sorts the data values of columns (fields)
either in ascending or descending order. And then, it assigns the entry for each value.
SELECT employee_name

Create an INDEX : In SQL, we can easily create the Index using the following CREATE Statement:
FROM employees

CREATE INDEX Index_Name ON Table_Name ( Column_Name);


WHERE employee_id = (SELECT manager_id FROM departments WHERE department_name =
'Sales');
Here, Index_Name is the name of that index that we want to create, and Table_Name is the
name of the table on which the index is to be created. The Column_Name represents the name
Multiple-Row Subquery : Returns multiple rows.
of the column on which index is to be applied.If we want to create an index on the combination
of two or more columns, then the following syntax can be used in SQL:
SELECT employee_name
CREATE INDEX Index_Name ON Table_Name ( column_name1, column_name2, ....,
FROM employees column_nameN);

WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = Example for creating an Index in SQL : Let's take an Employee table :
1700);

Emp_Id Emp_Name Emp_Salary Emp_City Emp_State


Multiple-Column Subquery : Returns multiple columns but only one row.

1001 Akshay 20000 Noida U.P


SELECT employee_name, salary

1002 Ram 35000 Jaipur Rajasthan


FROM employees

1003 Shyam 25000 Gurgaon Haryana


WHERE (department_id, job_id) = (SELECT department_id, job_id FROM employees WHERE
employee_id = 101);
1004 Yatin 30000 Lucknow U.P

Operators In Subqueries : IN Operator : The IN operator is used to check if a value matches any
value in a set returned by a subquery.

SELECT employee_name The following SQL query creates an Index 'Index_state' on the Emp_State column of the
Employee table.

FROM employees
CREATE INDEX index_state ON Employee (Emp_State);

WHERE department_id IN (SELECT department_id FROM departments WHERE location_id =


1700); Suppose we want to create an index on the combination of the Emp_city and the Emp_State
column of the above Employee table. For this, we have to use the following query:

ANY Operator : The ANY operator is used to compare a value to any value in a set of values. It's
often used with comparison operators such as =, >, <, etc. CREATE INDEX index_city_State ON Employee (Emp_City, Emp_State);

SELECT employee_name Create UNIQUE INDEX : Unique Index is the same as the Primary key in SQL. The unique index
does not allow selecting those columns which contain duplicate values.This index is the best way
to maintain the data integrity of the SQL tables.
FROM employees

Syntax for creating the Unique Index is as follows : CREATE UNIQUE INDEX Index_Name ON
WHERE salary > ANY (SELECT salary FROM employees WHERE department_id = 20);
Table_Name ( Column_Name);

SOME Operator : The SOME operator is synonymous with the ANY operator. It's used to
Example for creating a Unique Index in SQL : Let's take the above Employee table. The following
compare a value to some values returned by a subquery.
SQL query creates the unique index index_salary on the Emp_Salary column of the Employee
table.
SELECT employee_name

CREATE UNIQUE INDEX index_salary ON Employee (Emp_Salary);


FROM employees

Rename an INDEX : We can easily rename the index of the table in the relational database using
WHERE salary > SOME (SELECT salary FROM employees WHERE department_id = 20); the ALTER command.

ALL Operator : The ALL operator is used to check if a value satisfies the condition against all Syntax : ALTER INDEX old_Index_Name RENAME TO new_Index_Name;
values in a set returned by a subquery.

Example for Renaming the Index in SQL : The following SQL query renames the index
SELECT employee_name 'index_Salary' to 'index_Employee_Salary' of the above Employee table:

FROM employees ALTER INDEX index_Salary RENAME TO index_Employee_Salary;

WHERE salary > ALL (SELECT salary FROM employees WHERE department_id = 10); Remove an INDEX : An Index of the table can be easily removed from the SQL database using
the DROP command. If you want to delete an index from the data dictionary, you must be the
In this example, the query retrieves employee names where the salary is greater than all salaries owner of the database or have the privileges for removing it. Syntaxes for Removing an Index in
in the specified department. relational databases are as follows:

In Oracle database : DROP INDEX Index_Name;


In MySQL database : ALTER TABLE Table_Name DROP INDEX Index_Name; When should indexes be avoided : Although indexes are intended to enhance a database's
performance, there are times when they should be avoided.The following guidelines indicate
In Ms-Access database : DROP INDEX Index_Name ON Table_Name; when the use of an index should be reconsidered.Indexes should not be used on small tables.

In SQL Server Database : DROP INDEX Table_Name.Index_Name; Pseudocolumn in SQL : Pseudocolumn: A pseudo-column behaves like a table column but is not
actually stored in the table. You can select from pseudo-columns, but you cannot insert, update,
or delete their values. A pseudo-column is also similar to a function without arguments. This
Example for removing an Index in SQL : Suppose we want to remove the above 'index_Salary'
section describes these pseudo-columns:
from the SQL database. For this, we have to use the following SQL query:

1. CURRVAL and NEXTVAL: A sequence is a schema object that can generate unique sequential
DROP INDEX index_salary;
values. These values are often used for primary and unique keys. You can refer to sequence
values in SQL statements with these pseudocolumns: CURRVAL : Returns the current value of a
Alter an INDEX : An index of the table can be easily modified in the relational database using the sequence. NEXTVAL : Increments the sequence and returns the next value.
ALTER command.The basic syntax for modifying the Index in SQL is as follows:
Examples : SELECT STUDENTSEQ.currval FROM DUAL;
ALTER INDEX Index_Name ON Table_Name REBUILD;
INSERT INTO STUDENT VALUES (STUDENTSEQ.nextval, ‘BISHAL’, ‘JAVA’, 7902);
When should INDEXES not be used in SQL : The Indexes should not be used in SQL in the
following cases or situations : SQL Indexes can be avoided when the size of the table is small.
2. LEVEL : For each row returned by a hierarchical query, the LEVEL pseudocolumn returns 1 for
When the table needs to be updated frequently. Indexed should not be used on those cases
a root node, 2 for a child of a root, and so on.
when the column of a table contains a large number of NULL values.

3. ROWNUM: Oracle engine maintains the number of each record inserted by users in table. By
The SQL Indexes : SQL Indexes are special lookup tables that are used to speed up the process of
the help of ROWNUM clause we can access the data according to the record inserted.
data retrieval. They hold pointers that refer to the data stored in a database, which makes it
easier to locate the required data records in a database table.SQL Indexes work similar to the
index of a book or a journal.While an index speeds up the performance of data retrieval queries Example : SELECT * FROM EMP WHERE ROWNUM <= 3;
(SELECT statement), it slows down the performance of data input queries (UPDATE and INSERT
statements). However, these indexes do not have any effect on the data.SQL Indexes need their 4. ROWID : For each row in the database, the ROWID pseudocolumn returns a row\’s address.
own storage space within the database. Despite that, the users cannot view them physically as The ROWID contains 3 information about row address:
they are just performance tools.
FileNo : FileNo means Table Number.
The CREATE INDEX Statement : An index in SQL can be created using the CREATE INDEX
statement. This statement allows you to name the index, to specify the table and which column DataBlockNo : DataBlockNo means the space assigned by the oracle SQL engine to save the
or columns to index, and to indicate whether the index is in an ascending or descending order. record.
Preferably, an index must be created on column(s) of a large table that are frequently queried
for data retrieval. Syntax : The basic syntax of a CREATE INDEX is as follows −
RecordNo : Oracle engine maintains the record number for each record.

CREATE INDEX index_name ON table_name;


Example : SELECT ROWID, ename FROM emp WHERE deptno = 20;

Types of Indexes : There are various types of indexes that can be created using the CREATE
INDEX statement. They are:

Unique Indexes : Unique indexes are used not only for performance, but also for data integrity.
A unique index does not allow any duplicate values to be inserted into the table. It is
automatically created by PRIMARY and UNIQUE constraints when they are applied on a
database table, in order to prevent the user from inserting duplicate values into the indexed
table column(s). The basic syntax is as follows.

CREATE UNIQUE INDEX index_name

on table_name (column_name);

Single-Column Indexes : A single-column index is created only on one table column. The syntax
is as follows.

CREATE INDEX index_name

ON table_name (column_name);

Composite Indexes : A composite index is an index that can be created on two or more columns
of a table. Its basic syntax is as follows.

CREATE INDEX index_name

on table_name (column1, column2);

Implicit Indexes : Implicit indexes are indexes that are automatically created by the database
server when an object is created. For example, indexes are automatically created when primary
key and unique constraints are created on a table in MySQL database.

The DROP INDEX Statement : An index can be dropped using SQL DROP command. Dropping an
index can effect the query performance in a database. Thus, an index needs to be dropped only
when it is absolutely necessary. The basic syntax is as follows −

DROP INDEX index_name;

You might also like