DBMS Report Raj

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 66

SIDDARTHA INSTITUTE OF

SCIENCE AND TECHNOLOGY,


PUTTUR
(AUTONOMOUS)
(AFFILIATED TO JNTU, ANANTPUR)

DBMS REPORT

NAME: RAJ KUMAR YADAV


ROLL NO :214E1A05C0
BRANCH: CSE
SECTION: 2
SUBJECT: DATABASE MANAGEMENT
SYSTEM
FACULTY: G RAVIKUMAR
UNIT-I
Introduction: Database System Applications, Purpose of Database
Systems, View of Data, Data Abstraction, Data Independence, Data
Models, Database Languages, Database Architecture, Database Users and
Administrators.

Introduction to Data base design: ER diagrams, Entities, Attributes and


Entity sets, Relationships and Relationship sets.

What is a database?
Database is a collection of related data organised in a way that can be easily
accessed, managed, and updated.
For example, a university database might contain information about the
following:
• Entities such as students, faculty, courses, and classrooms.
• Relationships between entities, such as students' enrollment in courses, faculty
teaching courses, and the use of rooms for courses.
What is a DBMS?
A database management system, or DBMS, is software designed to assist in
maintaining and utilizing large collections of data.
It is a collection of programs used for managing data and simultaneously it
supports different types of users to create, manage, retrieve, update and store
information.

Database-System Applications
Databases are widely used. Here are some representative applications:
Enterprise Information
◦ Sales: For customer, product, and purchase information.
◦ Accounting: For payments, receipts, account balances, assets and other
accounting information.
◦ Human resources: For information about employees, salaries, payroll taxes,
and benefits, and for generation of paychecks.
◦ Manufacturing: For management of the supply chain and for tracking
production of items in factories, inventories of items in warehouses and stores,
and orders for items.
◦ Online retailers: For sales data noted above plus online order tracking,
generation of recommendation lists, and maintenance of online product
evaluations.
• Banking and Finance
◦ Banking: For customer information, accounts, loans, and banking transactions.
◦ Credit card transactions: For purchases on credit cards and generation of
monthly statements.
◦ Finance: For storing information about holdings, sales, and purchases of
financial instruments such as stocks and bonds; also for storing real-time market
data to enable online trading by customers and automated trading by the firm.
• Universities: For student information, course registrations, and grades (in
addition to standard enterprise information such as human resources and
accounting).
• Airlines: For reservations and schedule information. Airlines were among the
first to use databases in a geographically distributed manner.
• Telecommunication: For keeping records of calls made, generating monthly
bills, maintaining balances on prepaid calling cards, and storing information
about the communication networks.
Purpose of Database Systems
The purpose of DBMS is to transform the following −
 Data into information.
 Information into knowledge.
 Knowledge to the action.
The diagram given below explains the process as to how the transformation of
data to information to knowledge to action happens respectively in the DBMS –

DATA
INFORMATION
KNOWLEDGE ACTION
(Unprocessed
(Processed)
information
View of Data in DBMS
 Abstraction is one of the main features of database systems.
 Hiding irrelevant details from user and providing abstract view of data to
users, helps in easy and efficient user-database interaction.
 The three level of DBMS architecture, The top level of that architecture is
―view level. The view level provides the ―view of data‖ to the users and hides
the irrelevant details such as data relationship, database schema, constraints,
security etc from the user.

Data Abstraction in DBMS


Database systems are made-up of complex data structures. To ease the user
interaction with database, the developers hide internal irrelevant details from
users. This process of hiding irrelevant details from user is called data
abstraction.

We have three levels of abstraction:


Physical level: This is the lowest level of data abstraction. It describes how data
is actually stored in database. You can get the complex data structure details at
this level.
Logical level: This is the middle level of 3-level data abstraction architecture. It
describes what data is stored in database.
View level: Highest level of data abstraction. This level describes the user
interaction with database system.

Data Independence in DBMS:


Data independence is the ability to modify the scheme without affecting the
programs and the application to be rewritten. Data is separated from the
programs, so that the changes made to the data will not affect the program
execution and the application.
There are two levels of data independence based on three levels of abstraction.
These are as follows –
 Physical Data Independence
 Logical Data Independence

Physical Data Independence


Physical Data Independence means changing the physical level without
affecting the logical level or conceptual level. Using this property, we can
change the storage device of the database without affecting the logical schema.
The changes in the physical level may include changes using the following –
 A new storage device like magnetic tape, hard disk, etc.
 A new data structure for storage.
 A different data access method or using an alternative files organization
technique.
 Changing the location of the database.
Logical Data Independence
Logical view of data is the user view of the data. It presents data in the form that
can be accessed by the end users.
Codd‘s Rule of Logical Data Independence says that users should be able to
manipulate the Logical View of data without any information of its physical
storage. Software or the computer program is used to manipulate the logical
view of the data.
Database administrator is the one who decides what information is to be kept in
the database and how to use the logical level of abstraction. It provides the
global view of Data. It also describes what data is to be stored in the database
along with the relationship.
The data independence provides the database in simple structure. It is based on
application domain entities to provide the functional requirement. It provides
abstraction of system functional requirements. Static structure for the logical
view is defined in the class object diagrams. Users cannot manipulate the
logical structure of the database.
The changes in the logical level may include –
 Change the data definition.
 Adding, deleting, or updating any new attribute, entity or relationship in the
database.

DATA MODELS:
 Data Model is the modelling of the data description, data semantics, and
consistency constraints of the data.
 It provides the conceptual tools for describing the design of a database at each
level of data abstraction.
 Therefore, there are following four data models used for understanding the
structure of the database:
Four Types of DBMS systems are:
 Hierarchical database
 Network database
 Relational database
 ER model database
Hierarchical DBMS
In a Hierarchical database, model data is organized in a tree-like structure. Data
is Stored Hierarchically (top down or bottom up) format. Data is represented
using a parent-child relationship. In Hierarchical DBMS parent may have many
children, but children have only one parent.

COLLEGE

DEPARTMENT INFRASTRUCTURE

COURSE LECTURER STUDENT

Network Model
The network database model allows each child to have multiple parents. It helps
you to address the need to model more complex relationships like as the
orders/parts many-to-many relationship. In this model, entities are organized in
a graph which can be accessed through several paths.

Relational model Relational


DBMS is the most widely used DBMS model because it is one of the easiest.
This model is based on normalizing data in the rows and columns of the tables.
Relational model stored in fixed structures and manipulated using SQL.
Entity-Relationship Model
Entity-Relationship (ER) Model is based on the notion of real-world entities and
relationships among them. While formulating real-world scenario into the
database model, the ER Model creates entity set, relationship set, general
attributes and constraints.

PCs and a workstation which are connected via the network.


 DBMS architecture depends upon how users are DBMS languages
Database languages are used to read, update and store data in a database. There
are several such languages that can be used for this purpose; one of them is SQL
(Structured Query Language).

DATABASE LANGUAGE

DDL DML TCL DCL

CREATE INSERT COMMIT GRANT


ALTER SELECT SAVEPOINT REVOKE
TRUNCATE UPDATE ROLL BACK
DROP DELETE

DDL : Data Definition Language


COMMAND DESCRIPTION
CREATE Creates a new table, a view of a table or, other object
in the database.
ALTER Modifies an existing database object, such as a table.
TRUNCATE This command is used to delete all the rows from the
table and free the space containing the table.
DROP Deletes an entire table, a view of a table or other in the
database.
1.CREATE A TABLE
Syntax:
create table table_name(attribute_name1 datatype(size),……..,attribute_nameN
datatype(size));
Query:
create table cseraj(Sno number(10), name varchar2(20), marks number);
Output:
SQL> desc cseraj;
Name Null? Type
………………………. ……………… ………………
SNO NUMBER(10)
NAME VARCHAR2(20)
MARKS NUMBER

2.ALTER
1. add
2. modify
3. rename
4. drop

2.1. ADD
Syntax:
alter table table_name add (new_attribute_name datatype(size),…..,N);
Query:
alter table cseraj add(aad number(20), phone number(10));
Output:
SQL> desc cseraj;
Name Null? Type
………………………. ……………… ………………
SNO NUMBER(10)
NAME VARCHAR2(20)
MARKS NUMBER
ADD NUMBER(20)
PHONE NUMBER(10)
2.2. MODIFY
Syntax:
alter table table name modify (oldcolumnname datatype (new size));
Query:
alter table cseraj modify (name varchar2(15));
Output:
SQL> desc cseraj;
Name Null? Type
………………………. ……………… ………………
SNO NUMBER(10)
NAME VARCHAR2(15)
MARKS NUMBER
ADD NUMBER(20)
PHONE NUMBER(10)

2.3 RENAME
Syntax:
alter table tablename rename column oldcolumnname to
newcolumnname;
Query:
alter table cseraj rename column sno to no;
SQL> desc cseraj;
Name Null? Type
………………………. ……………… ………………
NO NUMBER(10)
NAME VARCHAR2(15)
MARKS NUMBER
ADD NUMBER(20)
PHONE NUMBER(10)

2.4 DROP
Syntax:
alter table tablename drop column oldcolumnname;
Query:
alter table cseraj drop column marks;
Output:
SQL> desc cseraj;
Name Null? Type
………………………. ……………… ………………
NO NUMBER(10)
NAME VARCHAR2(15)
ADD NUMBER(20)
PHONE NUMBER(10)

3.TRUNCATE
Syntax:
truncate table tablename;
Query:
truncate table cseraj;
Output:
SQL> desc cseraj;
Name Null? Type
………………………. ……………… ………………
NO NUMBER(10)
NAME VARCHAR2(15)
ADD NUMBER(20)
PHONE NUMBER(10)

4.DROP
Syntax:
drop table tablename;
Query:
drop table raj1;
Output:
SQL> desc cseraj;
ERROR:
ORA-04043: object cseraj does not exist.

DML : Data Manipulation Language


COMMAND DESCRIPTION
SELECT Retrieves certain records from one or more tables.
INSERT Creates a record
UPDATE Modifies records
DELETE Deletes records

Consider a table cseraj with sno, sname, and marks as attributes..


1.INSERT
Syntax:
insert into table_name values(val1,val2,….,valN);
Query:
insert into cseraj values(501,’Raj’,85);
Output:
1 row inserted.
Dynamic Values:
Syntax:
insert into table_name values(&col1,’&col2’,….,&colN);
Query:
insert into cseraj values(&sno,’&sname’,&marks);
Output:
Enter value for sno: 502
Enter value for sname: Deepak
Enter value for marks: 90
1 row created.
Query:
insert into cseraj values(503,’Suraj’,75);
Output:
1 row created.

2.SELECT
Syntax:
Select columnlists from table_name;
(OR)
Select * from table_name;
Query:
Select * from cseraj;
Output:
SNO SNAME MARKS
501 Raj 85
502 Deepak 90
503 Suraj 75

3.UPDATE
Syntax:
Update table_name set column_name=new_value where condition;
Query:
Update cseraj set marks=80 where sno=503;
Output:
1 row updated.
Select * from cseraj;
SNO SNAME MARKS
501 Raj 85
502 Deepak 90
503 Suraj 80

4.DELETE
Syntax:
Delete from table_name where condition;
Query:
Delete from cseraj where sno=503;
Output:
1 row deleted.
Select * from cseraj;
SNO SNAME MARKS
501 Raj 85
502 Deepak 90

DCL: Data Control Language


DCL includes commands such as GRANT and REVOKE which mainly deals
with the rights, permissions and other controls of the database system.
Examples of DCL commands:
GRANT-gives user’s access privileges to database.
REVOKE-withdraw user’s access privileges given by using the GRANT
command
GRANT:
Syntax:
Create user username identified by password;
Grant create session to username;
Grant privileges on tablename to username;

Query:
Create user raj identified by 123;
Grant create session to raj;
Grant select on cseraj to raj;
SQL> Conn
Enter user-name: raj
Enter password: 123
SQL> select * from system.cseraj;
SNO SNAME MARKS
501 Raj 85
502 Deepak 90
REVOKE:
Syntax:
Revoke privileges on tablename from username;
Query:
Revoke select on cseraj from raj;
Output:
Privilege revoked.

TCL : Transaction Control Language


TCL commands deals with the transaction within the database.
Examples of TCL commands:
COMMIT– commits a Transaction.
ROLLBACK– rollbacks a transaction in case of any error occurs.
SAVEPOINT–sets a savepoint within a transaction.
SET TRANSACTION–specify characteristics for the transaction.

DBMS ARCHITECTURE
Database management systems architecture will help us understand the
components of database system and the relation among them.
The architecture of DBMS depends on the computer system on which it runs.
 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 connected to the database to
get their request done.
TYPES OF DBMS ARCHITECTURE
There are three types of DBMS architecture:
1. Single tier architecture
2. Two tier architecture
3. Three tier architecture
1-Tier Architecture
 In this type of architecture, the database is readily available on the client
machine, any request made by client doesn‘t require a network connection to
perform the action on the database.
 Any changes done here will directly be done on the database itself. It doesn't
provide a handy tool for end users.
 The 1-Tier architecture is used for development of the local application, where
programmers can directly communicate with the database for the quick
response.
2-Tier architecture
 In two-tier architecture, the Database system is present at the server machine
and the DBMS application is present at the client machine, these two machines
are connected with each other through a reliable network.
 back to the client. The application connection interface such as JDBC, ODBC
are used for the interaction between server and client.
 Whenever client machine makes a request to access the database present at
server using a query language like sql, the server perform the request on the
database and returns the result.

DATABASE server
SYSTEM

Application
client
User

3- Tier Architecture
 In three-tier architecture, another layer is present between the client machine
and server machine.
 In this architecture, the client application doesn‘t communicate directly with
the database systems present at the server machine, rather the client application.
 Communicates with server application and the server application internally
communicates with the database system present at the server.

DATA BASE USERS AND ADMINISTRATORS


Database Users
Database users are the persons who interact with the database and take the
benefits of database.They are differentiated into different types based on the
way they expect to interact with the system.
Naive users: They are the unsophisticated users who interact with the system
by using permanent applications that already exist.
Example: Online Library Management System, ATMs (Automated Teller
Machine), etc.
Application programmers: They are the computer professionals who interact
with system through DML. They write application programs.
Sophisticated users: They interact with the system by writing SQL queries
directly through the query processor without writing application programs.
Specialized users: They are also sophisticated users who write specialized
database applications that do not fit into the traditional data processing
framework.
Example: Expert System, Knowledge Based System, etc.
Database Administrators
The life cycle of database starts from designing, implementing to administration
of it. A database for any kind of requirement needs to be designed perfectly so
that it should work without any issues. Once all the design is complete, it needs
to be installed. Once this step is complete, users start using the database. The
database grows as the data grows in the database. When the database becomes
huge, its performance comes down. Also accessing the data from the database
becomes challenge. There will be unused memory in database, making the
memory inevitably huge. These administration and maintenance of database is
taken careby database Administrator – DBA.
A DBA has many responsibilities. A good performing database is in the hands
of DBA. Database Administrators coordinate all the activities of the database
system. They have all the permissions.

What is Relational Model?


Relational Model (RM) represents the database as a collection of relations. A
relation is nothing but a table of values. Every row in the table represents a
collection of related data values. These rows in the table denote a real-world
entity or relationship. The table name and column names are helpful to interpret
the meaning of values in each row. The data are represented as a set of relations.
In the relational model, data are stored as tables. However, the physical storage
of the data is independent of the way the data are logically organized.
Relational Model Concepts
1. Attribute: Each column in a Table. Attributes are the properties which define
a relation. e.g., Student_Rollno, NAME,etc.
2. Tables – In the Relational model the, relations are saved in the table format.
It is stored along with its entities. A table has two properties rows and columns.
Rows represent records and columns represent attributes.
3. Tuple – It is nothing but a single row of a table, which contains a single
record.
4. Relation Schema: A relation schema represents the name of the relation with
its attributes.
5. Degree: The total number of attributes which in the relation is called the
degree of the relation.
6. Cardinality: Total number of rows present in the Table.
7. Column: The column represents the set of values for a specific attribute.
8. Relation instance – Relation instance is a finite set of tuples in the RDBMS
system. Relation instances never have duplicate tuples.
9. Relation key - Every row has one, two or multiple attributes, which is called
relation key.
10. Attribute domain – Every attribute has some pre-defined value and scope
which is known as attribute domain.

ER model
 ER model stands for an Entity-Relationship model. It is a high-level data
model. This model is used to define the data elements and relationship
for a specified system.
 It develops a conceptual design for the database. It also develops a very
simple and easy to design view of data.
 In ER modelling, the database structure is portrayed as a diagram called
an entity-relationship diagram.
For example, Suppose we design a school database. In this database, the student
will be an entity with attributes like address, name, id, age, etc. The address can
be another entity with attributes like city, street name, pin code, etc and there
will be a relationship between them.
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an
entity can be represented as rectangles.
Consider an organization as an example- manager, product, employee,
department etc. can be taken as an entity.

a. Weak Entity
An entity that depends on another entity called a weak entity. The weak
entity doesn't contain any key attribute of its own. The weak entity is
represented by a double rectangle.

2. Attribute

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


represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It
represents a primary key. The key attribute is represented by an ellipse with
the text underlined.

b. Composite Attribute

An attribute that composed of many other attributes is known as a


composite attribute. The composite attribute is represented by an
ellipse, and those ellipses are connected with an ellipse.

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

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

d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived
attribute. It can be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from
another attribute like Date of birth.

3. Relationship
A relationship is used to describe the relation between entities. Diamond
or rhombus is used to represent the relationship
Types of relationship are as follows:
a. One-to-One Relationship
When only one instance of an entity is associated with the relationship,
then it is known as one to one relationship.

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

b. One-to-many relationship

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

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

c. Many-to-one relationship

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

For example, Student enrolls for only one course, but a course can have
many students.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than
one instance of an entity on the right associates with the relationship
then it is known as a many-to-many relationship.

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

Notation of ER diagram
Database can be represented using the notations. In ER diagram, many
notations are used to express the cardinality. These notations are as follows:
Relationship set in DBMS
The number of entity types which took part in the entity relationship is called
the degree of relationships.
There are three different types of degree of relationships, they are as follows −
• Unary relationship
• Binary relationship
• Ternary relationship

Unary relationship
It is the relationship between the instances of a single entity type. It is also
called a recursive relationship.
Example
A person is married is a one-to-one relationship between the instances of
Person entity type of unary relationship.

Binary relationship
It is the relationship between the instances of two different entity types. Two
entities will participate in the relationship.
For Example
Person and events are two different entity types which are related by using the
relationship called ―attend.

Ternary relationship
A simultaneous relationship between the instances of three entity types with
unique attributes is called a ternary relationship.
Example
Consultant, client and contract are three different entities with different
attributes.
These three entities are related with a single relationship called ―signs.

KEYS IN DBMS

KEYS in DBMS is an attribute or set of attributes which helps you to


identify a row(tuple) in a relation(table). They allow you to find the
relation between two tables. Keys help you uniquely identify a row in a
table by a combination of one or more columns in that table. Key is
also helpful for finding unique record or row from the table. Database
key is also helpful for finding unique record or row from the table.
Why we need a Key?
Here are some reasons for using sql key in the DBMS system.
• Keys help you to identify any row of data in a table. In a real-world
application, a table could contain thousands of records. Moreover, the
records could be duplicated. Keys ensure that you can uniquely identify
a table record despite these challenges.
• Allows you to establish a relationship between and identify the relation
between tables  Help you to enforce identity and integrity in the
relationship.

Types of Keys in Database Management System


There are mainly seven different types of Keys in DBMS and each key has
its different functionality:
• Super Key - A super key is a group of single or multiple keys which
identifies rows in a table.
• Primary Key - is a column or group of columns in a table that uniquely
identify every row in that table.
• Candidate Key - is a set of attributes that uniquely identify tuples in a
table. Candidate Key is a super key with no repeated attributes.
• Alternate Key - is a column or group of columns in a table that uniquely
identify every row in that table.
• Foreign Key - is a column that creates a relationship between two
tables. The purpose of Foreign keys is to maintain data integrity and
allow navigation between two different instances of an entity.
• Compound Key - has two or more attributes that allow you to
uniquely recognize a specific record. It is possible that each column
may not be unique by itself within the database.
• Composite Key - An artificial key which aims to uniquely identify
each record is called a surrogate key. These kind of key are unique
because they are created when you don't have any natural primary key.
• Surrogate Key - An artificial key which aims to uniquely identify
each record is called a surrogate key. These kind of key are unique
because they are created when you don't have any natural primary key.
Primary key example:
CREATE TABLE Persons (ID int NOT NULL,LastName varchar(255)
NOT NULL,
FirstName varchar(255), Age int,PRIMARY KEY (ID));
Create Primary Key (ALTER TABLE statement)

Syntax
The syntax to create a primary key using the ALTER TABLE statement in
SQL is:

ALTER TABLE table_name


ADD CONSTRAINT constraint_name
PRIMARY KEY (column1, column2, ... column_n);
FOREIGN KEY on CREATE TABLE
The following SQL creates a FOREIGN KEY on the "PersonID" column
when the "Orders" table is created:

CREATE TABLE Orders (OrderID int NOT NULL, OrderNumber int


NOT NULL, PersonID int,PRIMARY KEY (OrderID),FOREIGN KEY
(PersonID) REFERENCES Persons(PersonID));

Integrity Constraints
o Integrity constraints are a set of rules. It is used to
maintain the quality of information.
o Integrity constraints ensure that the data insertion, updating, and
other processes have to be performed in such a way that data
integrity is not affected.
o Thus, integrity constraint is used to guard against accidental
damage to the database.

Types of Integrity Constraint

1. Domain constraints
o Domain constraints can be defined as the definition of a valid set of
values for an attribute.
o The data type of domain includes string, character, integer, time,
date, currency, etc. The value of the attribute must be available in the
corresponding domain.

Example:
2.Entity integrity constraints

o The entity integrity constraint states that primary key

value can't be null.

o This is because the primary key value is used to identify individual rows in
relation and if the primary key has a null value, then we can't identify those
rows.
o A table can contain a null value other than the primary key field.

3.Referential Integrity Constraints

o A referential integrity constraint is specified


between two tables.

o In the Referential integrity constraints, if a foreign key in Table 1 refers to


the Primary Key of Table 2, then every value of the Foreign Key in Table 1
must be null or be available in Table 2.
3.Referential Integrity Constraints
o A referential integrity constraint is specified between two tables. o In the
Referential integrity constraints, if a foreign key in Table 1 refers to the
Primary Key of Table 2, then every value of the Foreign Key in Table 1 must
be null or be available in Table 2.

4. Key constraints
a. Keys are the entity set that is used to identify an entity within its entity set
uniquely.
b. An entity set can have multiple keys, but out of which one key will be the
primary key.
A primary key can contain a unique and null value in the relational table.
UNIT-II
Relational Algebra and Calculus: Relational Algebra - Selection and
Projection, Set operations, Renaming, Joins.
Form of Basic SQL Query- Examples of Basic SQL Queries, Introduction to
Nested Queries, Correlated Nested Queries, Set - Comparison Operators,
Aggregate Operators, NULL values - Comparison using Null values,
Disallowing NULL values, Triggers and Active Data bases.

Relational Algebra
• Relational Algebra is procedural query language, which takes Relation as
input and generates relation as output. Relational algebra mainly provides
theoretical foundation for relational databases and SQL.
• Relational algebra is a procedural query language, it means that it tells
what data to be retrieved and how to be retrieved.
• Relational Algebra works on the whole table at once, so we do not have
to use loops etc to iterate over all the rows (tuples) of data one by one.
• All we have to do is specify the table name from which we need the data,
and in a single line of command, relational algebra will traverse the entire
given table to fetch data for you.
Basic/Fundamental Operations:

1. Select (σ)
2. Project (∏)
3. Union ( )
4. Intersect (∩)
5. Set Difference (-)
6. Cartesian product (X)
7. Rename (ρ)

Consider the table ‘STUDENT’

ID NAME BRANCH MARKS


101 RAJ CIVIL 75
102 DEEPAK EEE 85
103 SURAJ MECH 65
104 PRITI ECE 90
105 KRITI CSE 95

The SELECT Operation(σ)


 The SELECT operation selects tuples that satisfy a given predicate.
 The selection is denoted by σ(sigma).
 The select operation is a unary operation, because it operates on one
relation.
Syntax:
σ column= value (table_name);
Query:
σ name= raj (student);

Output:
ID NAME BRANCH MARKS
101 RAJ CIVIL 75

The PROJECT Operation (∏):


• Project operation is used to project only a certain set of attributes of a
relation. In simple words, If you want to see only the names all of the
students in the Student table, then you can use Project Operation.
• It will only project or show the columns or attributes asked for, and will
also remove duplicate data from the columns.
• Syntax of Project Operator (∏)
Syntax:
∏ column_name1, column_name2, .... , column_nameN(table_name) ;

Query:
∏ ID, NAME, MARKS (STUDENT);
OUTPUT

ID NAME MARKS
101 RAJ 75
102 DEEPAK 85
103 SURAJ 65
104 PRITI 90
105 KRITI 95

The RENAME Operation(ρ)


 This operation is used to rename the output relation for any query
operation which returns result like Select, Project etc. Or to simply
rename a relation(table) .
 The rename operation is used to rename the output relation. It is
denoted by rho (ρ).

Syntax:
ρ (newRelation, oldRelation);

Example:
We can use the rename operator to rename STUDENT relation to
STUDENT1.
Query:
ρ (STUDENT1, STUDENT)

The UNION Operation:


 The Union operation is denoted by U symbol.
 It includes all tuples that are in table R and S.
 It also eliminates duplicate tuples.
 For a union operation to be valid, the following condition must valid:
1. R and S must be have the same number of attributes.
2. Duplicate tuples should be automatically removed.
Consider the following tables:

Table R

CID CNAME
504 COA
505 DBMS
506 OOPS
Table S

CID CNAME
506 OOPS
507 OS
508 MEFA

Syntax:
Table1 U Table2;
Query:
RUS
Output:
CID CNAME
504 COA
505 DBMS
506 OOPS
507 OS
508 MEFA

The INTERSECT Operation


 An intersection is defined by the symbol ∩.
 It consists of a set of all tuples that are in both R and S.
Syntax:
Table1 ∩ Table2
Query:
R∩S
Output:
CID CNAME
506 OOPS

The SET DIFFERENCE Operation


 It is denoted by – (minus) symbol.
 The result of R-S is a relation which includes all tuples that are in R
but not in S.
Syntax:
Table1 – Table2
Query:
R–S
Output:
CID CNAME
504 COA
505 DBMS

The CARTESIAN PRODUCT


 Cartesian product is an operation used to merge columns from
two relations.
 It is denoted by cross (×).
Consider the following tables.
Table STUDENT
SID SNAME
101 RAJ
102 DEEPAK
103 SURAJ

Table COURSE
CID CNAME
504 COA
505 DBMS

Syntax:
Table1 × Table2
Query:
STUDENT × COURSE
Output:
SID SNAME CID CNAME
101 Raj 504 COA
101 Raj 505 DBMS
102 Deepak 504 COA
102 Deepak 505 DBMS
103 Suraj 504 COA
103 Suraj 505 DBMS
JOIN IN DBMS
• A JOIN clause is used to combine rows from two or more tables, based on
a related column between them.
• Join in DBMS is a binary operation which allows you to combine join
product and selection in one single statement.
• The goal of creating a join condition is that it helps you to combine the data
from two or more DBMS tables.
• The tables in DBMS are associated using the primary key and foreign keys.
• A Join can be broadly divided into two types :
• INNER JOIN
• OUTER JOIN

JOIN

INNER JOIN OUTER JOIN

Consider the following tables.


Table STUDENT
SID SNAME BRANCH_ID
1 Raj 501
2 Deepak 201
3 Suraj 101
4 Rahul 301

Table BRANCH
BRANCH_ID BRANCH_NAME
101 CE
102 EEE
401 ECE

INNER JOIN
• Inner join is a join that can be used to return all the values that have
matching values in both the tables.

• The inner join can be further divided into two types:


1. Equi Join
2. Natural Join

Equi Join
Equi Join is an inner join that uses the equivalence condition for fetching the
values of two tables.
Syntax:
Select tablename.columnlists from table1name inner join table2name on
condition.
Query:
Select student.sid, student.sname, branch.branch_name from student
INNER JOIN branch on student.branch_id = branch.branch_id;
Output:
SID SNAME BRANCH_NAME
2 Deepak EEE
3 Suraj CE
Natural Join
 Natural Join is an inner join that returns the values of the two tables on
the basis of a common attribute that has the same name and domain.
 It does not use any comparison operator.
 It also removes the duplicate from the results.
Syntax:
Select * from table1name natural join table2name;
Query:
Select * from student natural join branch;
Output:
SID SNAME BRANCH_ID BRANCH_NAME
2 Deepak 201 EEE
3 Suraj 101 CE

OUTER JOIN
Outer join is a join that can be used to return in both the tables whether it has
matching record in both the tables or not.
The outer join can be further divided into three types:
1. Left Outer Join
2. Right Outer Join
3. Full Outer Join
Left Outer Join
The SQL left join returns all the values from left table and the matching
values from the right table. If there is no matching join value, it will return
NULL.
Syntax:
SELECT table1.column1, table1.column2 FROM
table1
LEFT OUTER JOIN
table2
ON table1.matching_column = table2.matching_column;
Query:
Select student.sid, student.sname, branch.branch_id FROM
STUDENT
LEFT OUTER JOIN
BRANCH
ON student.branch_id = branch.branch_id;
Output:
SID SNAME BRANCH_NAME
1 Raj NULL
2 Deepak EEE
3 Suraj CE
4 Rahul NULL

Right Outer Join


In SQL, RIGHT JOIN returns all the values from the values from the rows
of right table and the matched values from the left table. If there is no
matching in both tables, it will return NULL.
Syntax:
SELECT table1.column1, table1.column2 FROM table1
RIGHT OUTER JOIN
table2 ON table1.matching_column = table2.matching_column;
Query:
SELECT student.sid, student.sname, branch.branch_name FROM
STUDENT
RIGHT OUTER JOIN
BRANCH
ON student.branch_id = branch.branch_id;
Output:

SID SNAME BRANCH_NAME


2 Deepak EEE
3 Suraj CE
NULL NULL ECE

Full Outer Join


In SQL, FULL JOIN is the result of a combination of both left and
right outer join. Join tables have all the records from both tables. It
puts NULL on the place of matches not found.
Syntax:
SELECT table1.column1, table1.column2 FROM table1
FULL JOIN table2 ON table1.matching_column =
table2.matching_column;
Query:
SELECT student.sid, student.sname, branch.branch_name FROM
STUDENT
FULL OUTER JOIN
BRANCH
ON student.branch_id = branch.branch_id;
Output:
SID SNAME BRANCH_NAME
1 Raj NULL
2 Deepak EEE
3 Suraj CE
4 Rahul NULL
NULL NULL ECE

DIVISION OPERATOR
The division operator is used for queries which involve the ‘ALL’. It is not
supported by SQL.
R1÷R2 = tuples of R1 associated with all tuples of R2.
Consider tables R1 and R2.
Table R1
NAME COURSE
JAVA B.TECH
DBMS M.TECH
DBMS B.TECH
PYTHON B.TECH

Table R2
COURSE
B.TECH
M.TECH
Query:
Retrieves the name of the subject that is taught in all courses.
R1 ÷ R2
Output:
NAME
DBMS

Relational Calculus:

Relational calculus is a non-procedural query language that tells the system


what data to be retrieved but doesn‘t tell how to retrieve it. Relational
Calculus exists in two forms:

1. Tuple Relational Calculus (TRC)


2. Domain Relational Calculus (DRC)
Tuple Relational Calculus
Tuple Relational Calculus in DBMS uses a tuple variable (t) that goes to each
row of the table and checks if the predicate is true or false for the given row.
Depending on the given predicate condition, it returns the roe or part of the row.
A tuple relational calculus expression is of the form
{t|P(t)}
Where t is the tuple variable that runs over every
row
P(t) is the predicate logic expression or condition.
Consider a customer table.
CID NAME ZIPCODE
1 Raj 12345
2 Deepak 13546
3 Suraj 45213
4 Rahul 23546
5 Amit 12345
Example:
A TRC query to get all the data of customers whose zipcode is 12345.
Query:
{t\|t ∈ CUSTOMER ^ t.ZIPCODE = 12345}
Output:
CID NAME ZIPCODE
1 Raj 12345
5 Amit 12345

Domain Relational Calculus


Domain Relational Calculus uses domain variables to get the column values
required from the database based on the predicate expression or condition.
The Domain Relational Calculus expression is of the form
{<x1,x2,……,xn>|P(x1,x2,…….,xn)}
Where <x1,x2,….,xn> are domain variables usd to get the column values
required
P(x1,x2,…..xn) is the predicate expression or condition.
Example:
A DRC query to get the data of all customers with zipcode 12345.
Query:
{<x1,x2,x3>\|<x1,x2> ∈ CUSTOMER ^ x3= 12345}
Output:
CID NAME ZIPCODE
1 Raj 12345
5 Amit 12345

SUBQUERY (OR) NESTED QUERY


A subquery or nested query return data that will be used in the query as a
condition to further restrict the data to be retrieved.

Rules for Sub Queries:


1. Subqueries must be enclosed within parentheses.
2. A subquery can have only one column in the select clause unless multiple
column are in the main query for the subquery to compare its selected
column.
3. An ORDER BY command cannot be used in a subquery. The GROUP
BY can be used.
4. A subquery cannot be immediately enclosed in a set function.
Subqueries are most frequently used with the SELECT statement.

Syntax:
SELECT columnlists from tablename WHERE colunmname operator
(SELECT columnlists FROM tablename where condition);
Consider the CUSTOMER table having the following records:
ID NAME AGE ADDRESS SALARY
1 Ramesh 35 Puttur 2000.0
2 Rajesh 25 Tirupati 2500.0
3 Suresh 32 Patna 1500.0
4 Komal 40 Delhi 2800.0
5 Hardik 30 Mumbai 3000.0

Query:
SELECT * from customer where id in (SELECT id from customer
where salary > 2000.0);
Output:
ID NAME AGE ADDRESS SALARY
2 Rajesh 25 Tirupati 2500.0
4 Komal 40 Delhi 2800.0
5 Hardik 30 Mumbai 3000.0

Correlated Subquery:
 Correlated subqueries are used for row-by-row processing. Each
subquery is executed once for every row of the outer query.
 A correlated subquery is evaluated once for each row processed by the
parent statement. The parent statement can be a SELECT, UPDATE, or
DELETE statement.
 A correlated subquery is one way of reading every row in a table and
comparing values in each row against related data.
Syntax:
SELECT column1, column2, ……,
FROM table1 outer
WHERE column1 operator
(SELECT column1, column2,
FROM table2
Query: WHERE expr1 = outer.expr2);
SELECT name, salary, id
FROM customer outer
WHERE salary >
(SELECT AVG(salary)
FROM customer
WHERE id =
outer.id group by id);
Output:
ID NAME AGE ADDRESS SALARY
2 Rajesh 25 Tirupati 2500.0
4 Komal 40 Delhi 2800.0
5 Hardik 30 Mumbai 3000.0

SET COMPARISON OPERATOR


 A comparison (or relational) operator is a mathematical symbol which is used
to compare two values. Comparison operators are used in conditions that
compares one expression with another.
 The result of a comparison can be TRUE, FALSE, or UNKNOWN (an operator
that has one or two NULL expressions returns UNKNOWN).

The following table describes different types of comparison operators -

Operator Description Operates on

= Equal to. Any compatible data types

> Greater than. Any compatible data types

< Less than. Any compatible data types

>= Greater than equal to. Any compatible data types

<= Less than equal to. Any compatible data types

<> Not equal to. Any compatible data types

Syntax:
SELECT columnlists FROM table
WHERE expr1 <comparison operator> expr2;

Equal to (=) Operator


The equal to operator is used for equality test within two numbers or expressions.
Query:
SELECT * from customer WHERE salary = 2500;
Output:
ID NAME AGE ADDRESS SALARY
2 Rajesh 25 Tirupati 2500.0
Greater than (>) operator
The greater than operator is used to test whether an expression (or number) is greater
than another one.
Query:
SELECT * from customer WHERE age > 30;
Output:
ID NAME AGE ADDRESS SALARY
1 Ramesh 35 Puttur 2000.0
3 Suresh 32 Patna 1500.0
4 Komal 40 Delhi 2800.0

Less than (<) Operator


The less than operator is used to test whether an expression (or number) is less than
another one.
Query:
SELECT * from customer WHERE age<32;
Output:
ID NAME AGE ADDRESS SALARY
2 Rajesh 25 Tirupati 2500.0
5 Hardik 30 Mumbai 3000.0

Greater than or Equal to (>=) Operator


The greater than equal to operator is used to test whether an expression (or number) is
either greater than or equal to another one.
Query:
SELECT * from customer WHERE age >=30;
Output:
ID NAME AGE ADDRESS SALARY
1 Ramesh 35 Puttur 2000.0
3 Suresh 32 Patna 1500.0
4 Komal 40 Delhi 2800.0
5 Hardik 30 Mumbai 3000.0
Less than or Equal to (<=) Operator
Query:
SELECT * from customer WHERE age <=30;
Output:
ID NAME AGE ADDRESS SALARY
2 Rajesh 25 Tirupati 2500.0
5 Hardik 30 Mumbai 3000.0

Not Equal to (<>) Operator


Query:
SELECT * from customer WHERE age <>30;
Output:
ID NAME AGE ADDRESS SALARY
1 Ramesh 35 Puttur 2000.0
2 Rajesh 25 Tirupati 2500.0
3 Suresh 32 Patna 1500.0
4 Komal 40 Delhi 2800.0

AGGREGATE OPERATORS
 SQL aggregation function is used to perform the calculations on
multiple rows of a single column of a table. It returns a single value.
 It is also used to summarize the data.
 SQL provides following aggregate functions:
Consider a student table:
SID NAME MARKS
101 A 85
102 B 80
103 C 75
104 D 65

1. COUNT ()
It returns the number of rows in a database table.
Syntax:
COUNT (attribute)
Query:
SELECT COUNT (sid) from student;
Output:
4

2. SUM ()
It returns the total sum of a numeric column.
Syntax:
SUM (attribute)
Query:
SELECT SUM (marks) from student;
Output:

SUM
305

3. AVG ()
It calculates the average of a set of values.
Syntax:
AVG (attribute)
Query:
SELECT AVG (marks) from student;
Output:
AVG
76
4. MIN ()
It returns the lowest value (minimum) in a set of non-null values.
Syntax:
MIN (attributes)
Query:
SELECT MIN (marks) from student;
Output:

MIN
65

5. MAX ()
It returns the highest value (maximum) in a set of non-null values.
Syntax:
MAX (attribute)
Query:
SELECT MAX (marks) from student;
Output:

MAX
85

ADVANCED AGGREGATE FUNCTIONS


The advanced aggregate functions available in SQL are:
1. ORDER BY
2. GROUP BY
3. HAVING
ORDER BY
 The ORDER BY statement in SQL is used for sort the fetched data in
either ascending or descending according to one or more columns.
 By default ORDER BY sorts the data in ascending order.
Consider a student table:
SID NAME MARKS
3 C 85
2 B 95
4 D 60
1 A 75

Syntax:
SELECT * from table ORDER BY column ASC/DESC;
Query:
SELECT * from student ORDER BY sid ASC;
Output:
SID NAME MARKS
1 A 75
2 B 95
3 C 85
4 D 60

GROUP BY
 The GROUP BY statement in SQL is used to arrange identical data into
groups with the help of some functions.
 If a particular column has same values in different rows then it will
arrange these row in a group.
Consider STUDENT table.
SID SNAME MARKS
1 Harsh 85
2 Raj 75
3 Ashish 70
4 Harsh 60
5 Ashish 90

Syntax:
SELECT column1, function_name (column2) from tablename
WHERE condition GROUP BY column1, column2;
Query:
SELECT sname, sum (marks) from student GROUP BY sname;
Output:
SNAME MARKS
Harsh 145
Raj 75
Ashish 160

HAVING
 The HAVING clause is used to apply a filter on the result of GROUP BY
based on the specified condition.
Syntax:
SELECT column1, function (column2) from tablename
WHERE condition GROUP BY column1, column2 HAVING
condition;
Query:
SELECT sname, sum (marks) as marks from student GROUP BY
sname
HAVING sum (marks)>100;
Output:
SNAME MARKS
Harsh 145
Ashish 160

NULL VALUES
 SQL supports a specific value known as NULL which is used to represent
the value of attributes that may be unknown (or) not apply to a tuple.
 It is important to know that a NULL value is different from ZERO value.
 A NULL value is used to represent a missing value.
 Each NULL value is considered to be different from every other NULL in
database.
Comparison Using NULL Values:

 SQL allows the use of NULL values to indicate absence of


information about the value of an attribute.
 We can use to special keyword NULL in a predicate to test for
‘NULL value’.
 The predicate is “NOT NULL” tests for the absence of null
value.
The general IS NULL syntax is

SELECT column-names

FROM table-name

WHERE column-name IS NULL

The general IS NOT NULL syntax is:

SELECT column-names

FROM table-name

WHERE column-name IS NOT NULL


Disallowing NULL values:
 A NOT NULL constraint in SQL is used to prevent inserting NULL
values into the specified column, considering it as a not accepted value
for that column.
 This means that we should provide a valid SQL NOT NULL value to that
column in the INSERT or UPDATE statements, as the column will
always contain data.

Views in SQL
 Views in SQL are considered as a virtual table. A view also contains
rows and columns.

 To create the view, we can select the fields from one or more tables
present in the database.

 A view can either have specific rows based on certain condition or


all the rows of a table.

Table: Student_Detail

STU_ID NAME ADDRESS

1 Stephan Delhi
2 Kathrin Noida
3 David Ghaziabad
4 Alina Gurugram

Table: Student_Marks
STU_ID NAME MARKS AGE
1 Stephan 97 19
2 Kathrin 86 21
3 David 74 18
4 Alina 90 20
5 John 96 18
1. Creating view
A view can be created using the CREATE VIEW statement. We can
create a view from a single table or multiple tables.

Syntax:
CREATE VIEW view_name AS SELECT column1, column2.....
FROM table_name WHERE condition;

Creating View from a single table

Query:
CREATE VIEW DetailsView AS SELECT NAME,
ADDRESS FROM Student_Details WHERE STU_ID
< 4;

Just like table query, we can query the view to view the data. SELECT *
FROM DetailsView;

Output:

NAME ADDRESS
Stephan Delhi
Kathrin Noida
David Ghaziabad

Creating View from multiple tables

View from multiple tables can be created by simply include multiple


tables in the SELECT statement.
In the given example, a view is created named MarksView from two
tables Student_Detail and Student_Marks.

Query:
CREATE VIEW MarksView AS
SELECT Student_Detail.NAME, Student_Detail.ADDRESS,
Student_Marks.MARKS FROM Student_Detail, Student_Mark
WHERE Student_Detail.NAME = Student_Marks.NAME;

To display data of View MarksView:


SELECT * FROM MarksView;

Output:

NAME ADDRESS MARKS


Stephan Delhi 97
Kathrin Noida 86
David Ghaziabad 74
Alina Gurugram 90

2. Deleting View

A view can be deleted using the Drop View


statement.
Syntax:
DROP VIEW view_name;
Example:
DROP VIEW MarksView;

Output:
VIEW dropped.

Uses of a View:
A good database should contain views due to the given reasons:
1. Restricting data access – Views provide an additional level
of table security by restricting access to a predetermined set of
rows and columns of a table.
2. Hiding data complexity – A view can hide the complexity that
exists in a multiple table join.
3. Simplify commands for the user –
Views allows the user to select information from multiple tables
without requiring the users to actually know how to perform a join.
4. Store complex queries –
Views can be used to store complex queries.
5. Rename Columns –
Views can also be used to rename the columns without affecting
the base tables provided the number of columns in view must
match the number of columns specified in select statement. Thus,
renaming helps to to hide the names of the columns of the base
tables.
6. Multiple view facility –
Different views can be created on the same table for different users.

Trigger:

 A trigger is a stored procedure in database which automatically invokes


whenever a special event in the database occurs. For example, a trigger
can be invoked when a row is inserted into a specified table or when
certain table columns are being updated.
 A trigger is a statement that the system executes automatically as a side
effect of a modification to the database.
 A trigger description contains three parts:
1. Event: An event is a change to the database which activates the
trigger.
2. Condition: A Query that is run when the trigger is activated is called
as condition.
3. Action: A procedure which is executed when the trigger is activated
and its condition is true.
Syntax for Creating a Trigger:

CREATE or [REPLACE] trigger trigger_name

[AFTER/BEFORE] DML/DDL on table_name

FOR EACH ROW

Where condition

DECLARE

BEGIN

END;

Types of Triggers:

1. Statement Level Trigger


2. Row Level Trigger
3. Before Triggers
4. After Triggers

Statement Level Trigger

It is fired only once for DML statement irrespective of number of rows


affected by statements.

Statement Level Trigger are the default type of trigger.

Query:

Create or [Replace] trigger student_info before update on student

BEGIN

dbms_output.put_line(“updated successfully”);

END;

Output:
Trigger Created.

Updated Successfully.

1 row updated.

Row Level Trigger:

It is fired for each row that is affected by DML command.

Query:

Create or [Replace] trigger student_info Before update on student

FOR EACH ROW

BEGIN

dbms_output.put_line(“Updated Successfully”);

END;

Output:

Trigger Created.

Update student set name=cse;

Updated successfully.

1 row updated.

1 row updated.

1 row updated.

Active Databases

 Active database is a database consisting of set of triggers. These


databases are very difficult to be maintained because of the complexity
that arises in understanding the effects of triggers.
 In such databases, DBMS initially verifies whether the particular trigger
specified in the statement that modifies the database is activated (or) not
prior to the execution of the statement.
 Features of active database:
1. It possesses all the concepts of the conventional database.
2. It supports all the functions of a traditional database like data
definition, data manipulation, storage management.
3. It detects event occurrence.
4. It must be able to evaluate conditions and to execute actions.
5. It means that it has to implement role execution.

UNIT-III
Introduction to Schema Refinement- Problems Caused by redundancy,
Functional Dependencies, Normal Forms - FIRST, SECOND, THIRD Normal
forms – BCNF.
Properties of Decompositions: Lossless join Decomposition, Dependency
preserving Decomposition - FOURTH Normal Form, FIFTH Normal form.

Redundancy:
Redundancy means having multiple copies of same data in the database. This
problem arises when a database is not normalized.
Suppose a table of student details having attributes Sid, sname, college, rank,
course.
SID SNAME CONTACT COLLEGE COURSE RANK
101 Raj 94712 SISTK B.TECH 1
102 Deepak 74939 SISTK B.TECH 1
103 Ravi 85078 SISTK B.TECH 1
104 Suraj 77695 SISTK B.TECH 1

As it can be observed that values of attribute college name, college rank, course,
is being repeated which can lead to problems.

Problems caused due to redundancy are:


1. Insertion Anomaly
If a student detail has to be inserted whose course is not being decided yet
then insertion will not be possible till the time course is decided for student.
This problem happens when the insertion of a data record is not possible
without adding some additional unrelated data to the record.
2. Deletion Anomaly
If the details of students in this table is deleted then the details of college
will also get deleted which should not occur common sense.
This anomaly happens when deletion of a data record results in losing some
unrelated information that was stored as part of the record that was deleted
from a table.
3. Updation Anomaly
Suppose if the rank of the college changes then changes will have to be over
the database which will be time-consuming and computationally
Costly.
If updation do not occur at all places then database will be in inconsistent
state.
FUNCTIONAL DEPENDENCY
Functional dependency is a relationship between attributes of a table dependent
on each other.
It was introduced by E.F Codd.
It helps in preventing data redundancy and gets to know about bad designs.
A functional dependency is denoted by an arrow “→“.
The functional dependency of X and Y is represented by X→Y.
Where, X = determinant set
Y = dependent attribute
Consider employee table
EMP_ID EMP_NAME SALARY CITY
1 A 2000 Puttur
2 B 3000 Tirupati
3 C 4000 Chennai

In this example, if we know the value of EMP_ID, we can obtain EMP_NAME,


SALARY, CITY.
Thus, EMP_NAME, SALARY and CITY are functionally dependent on
EMP_ID.
EMP_ID → EMP_NAME
EMP_ID → SALARY

Types of Functional Dependency


1. Trivial Functional Dependency
2. Non-Trivial Functional Dependency
3. Completely Non-Trivial Functional Dependency

Trivial Functional Dependency


In Trivial Functional Dependency, a dependent is always a subset of the
determinant.
If X → Y and Y is the subset of X,
Then it is called Trivial Functional Dependency.
For Example
ROLL NAME AGE
1 A 19

2 B 20
3 C 20

Here, {roll, name} → name


Is a trivial Functional Dependency
Since the department name is a subset of determinant set {roll, name}.
Similarly, roll → roll is also an example of Trivial Functional Dependency.

Non-Trivial Functional Dependency


In Non-Trivial Functional Dependency ,the dependent is strictly not a subset
of the determinant.
If X → Y and Y is not a subset of X, then it is called Non-Trivial Functional
Dependency.
For Example,
ROLL NAME AGE
1 A 19
2 B 20
3 C 20
Here, roll → name is a non-trivial functional dependency.
Since the dependent name is not a subset of determinant roll.
Similarly, {roll, name} → age is also an example of Non-Trivial Functional
Dependency.

You might also like