0% found this document useful (0 votes)
6 views89 pages

DBMS Final

The document provides an overview of Database Management Systems (DBMS), defining key concepts such as data, information, and various types of DBMS including RDBMS and NoSQL. It explains database languages like DDL, DML, DCL, and TCL, along with their specific commands and applications in different sectors. Additionally, it covers relational integrity rules, normalization, and various operations such as joins and transactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views89 pages

DBMS Final

The document provides an overview of Database Management Systems (DBMS), defining key concepts such as data, information, and various types of DBMS including RDBMS and NoSQL. It explains database languages like DDL, DML, DCL, and TCL, along with their specific commands and applications in different sectors. Additionally, it covers relational integrity rules, normalization, and various operations such as joins and transactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 89

DBMS

Database Management System


DATA and INFORMATION
• Data: It is a raw facts.
• Represented in form of numbers , words,
images, sounds, multimedia and animated
data.
• Information: Information is data that has been
converted into a more useful or intelligible
form.
DBMS

• DBMS is a software system


• Designed to manage and organize data in
structured manner.
• It allows users to create, modify, and query a
database
• Manage the security and access controls
• DBMS provides an environment to store
• Retrieve the data in co-invent and efficient
manner.
Key concepts:
• Data modeling
• Data storage and retrieval
• Concurrency control
• Data integrity and security
• Backup and recovery
DBMS can be classified into two types
• RDBMS (Relational Database Management
System)
• Non-Relational Database Management
System (NoSQL or Non-SQL )
• Designed to handle large-scale
• High-performance scenarios.
Database Languages
• Data Definition Language
• Data Manipulation Language
• Data Control Language
• Transactional Control Language
Data Definition Language

• DDL is the short name


• Deals with database schemas and descriptions
• How the data should reside in the database.
• CREATE: to create a database and its objects like
(table, index, views, store procedure, function,
and triggers)
• ALTER: alters the structure of the existing
database
• DROP: delete objects from the database
• TRUNCATE: remove all records from a table,
including all spaces allocated for the records are
removed
• COMMENT: add comments to the data dictionary
• RENAME: rename an object
Data Manipulation Language
• DML is the short name
• Deals with data manipulation
• SELECT, INSERT, UPDATE, DELETE, etc.,
• Used to store, modify, retrieve, delete and
update data in a database.
• SELECT: retrieve data from a database
• INSERT: insert data into a table
• UPDATE: updates existing data within a table
• DELETE: Delete all records from a database
table
• MERGE: UPSERT operation (insert or update)
Data Control Language
• DCL is short for Data Control Language
• Act as an access specifier to the database.
• Basically to grant and revoke permissions
• To users in the database
• GRANT: grant permissions to the user for running
DML(SELECT, INSERT, DELETE,…) commands on
the table
• REVOKE: revoke permissions to the user for
running DML(SELECT, INSERT, DELETE,…)
command on the specified table
Transactional Control Language
• TCL is short for Transactional Control Language
• Acts as an manager for all types of transactional
data and all transactions.
• Roll Back: Used to cancel or Undo changes made
in the database
• Commit: It is used to apply or save changes in the
database
• Save Point: It is used to save the data on the
temporary basis in the database
Applications of DBMS:
• Enterprise Information: Sales, accounting, human
resources, Manufacturing, online retailers.
• Banking and Finance Sector: Banks maintaining the
customer details, accounts, loans, banking transactions,
credit card transactions. Finance: Storing the information
about sales and holdings, purchasing of financial stocks and
bonds.
• University: Maintaining the information about student
course enrolled information, student grades, staff roles.
• Airlines: Reservations and schedules.
• Telecommunications: Prepaid, postpaid bills maintance.
E-R Model
Entity:
• An entity is referred to as a real-world object.
• It can be a name, place, object, class, etc.
• These are represented by a rectangle
Attributes:
• Description of the entity.
• These are represented by Eclipse
• It can be Age, Roll Number, or Marks for a Student.
Relationship:
• Used to define relations among different entities.
• Represented by Diamonds and Rhombus
Attributes
Simple attribute:
• Atomic values
• Cannot be broken down further .
• For example, student's age.

Composite attribute:
• Made up of more than one simple attribute.
• For example, student's address will contain, house no., street
name, pincode etc.

Derived attribute:
• Derived using other attributes.
• For example, average age of students in a class.
Attributes:
Single-valued attribute:
• They have a single value.
Multi-valued attribute:
• They can have multiple values.
Relation Database
• Collects different types of data sets
• Use tables, records, and columns.
• It is used to create a well-defined relationship
between database tables
• Relational databases can be easily stored.
• For example of relational databases such as
Microsoft SQL Server, Oracle Database,
MYSQL, etc
• A table has records (rows) and fields
(columns).
• Degree refers to the number of different
attributes or columns in a table
• Cardinality is used to count the total number
of tuples or rows in a table.
Different Types of Keys
• Primary Key
• Candidate Key
• Super Key
• Alternate Key
• Foreign Key
• Composite Key
+
Composite Key:
• Defined as combination of multiple columns
• These columns are used to identify all the
rows that are involved uniquely.
• Even though a single column can't identify
any row uniquely
• a combination of over one column can
uniquely identify any record.
Foreign key
• Is a column or columns of data in one table
that refers to the unique data values –
• often the primary key data -- in another table.
• Foreign keys link together two or more tables
in a relational database.
Relational Integrity Rules
Entity Integrity Rule:
• value of attribute of a primary key cannot be
null.
Referential Integrity Rule
• foreign key have a matching primary key.
• Reference from a table to another table
should be valid.
Relational Algebra and Calculus
Relational Algebra:
• It is a procedural language.
• The order is specified in which the operations
have to be performed.
• The basic operation included in relational
algebra are:
• 1. Select (σ) 2. Project (Π) 3. Union (U) 4. Set
Difference (-) 5. Cartesian product (X) 6.
Rename (ρ)
1. Selection(σ): It is used to select required tuples of
the relations.
3. Union(U): Union operation in relational algebra is
the same as union operation in set theory. Let there
are two tables: FRENCH and German
Student_Name Roll_Number Student_Name Roll_Number

Ram 01 Vivek 13

Mohan 02 Geeta 17

Vivek 13 Shyam 21

Geeta 17 Rohan 25
Student_Name
π(Student_Name)FRENCH U π(Student_Name)GERMAN Ram

Mohan

Vivek

Geeta

Shyam

Rohan
• 6. Rename(ρ): Rename is a unary operation
used for renaming attributes of a relation.
• ρ(a/b)R will rename the attribute 'b' of the
relation by 'a'.
• 7. Cross Product(X): Cross-product between
two relations. Let’s say A and B, so the cross
product between A X B will result in all the
attributes of A followed by each attribute of B.
Each record of A will pair with every record of
B.
• A B
Name Age Sex ID Course
Ram 14 M
1 DS
Sona 15 F

2 DBMS
Kim 20 M

AXB Name Age Sex ID Course

Ram 14 M 1 DS

Ram 14 M 2 DBMS

Sona 15 F 1 DS

Sona 15 F 2 DBMS

Kim 20 M 1 DS

Kim 20 M 2 DBMS
Types of Join operations
1. Natural Join
2. Outer Join
3. Equi Join
Natural Join
• It joins two tables based on the same attribute
name and dataypes.
• The resulting table will contain all the attributes
of both tables
• But keep only one copy of each common column.
Syntax
SELECT * FROM table1 NATURAL JOIN table2;
SELECT *
FROM Student NATURAL JOIN Student_Marks;
1
1

1
Inner Join or Equi join

• It joins two table on the basis of the column which is


explicitly specified in the ON clause.
• The resulting table will contain all the attributes from
both the tables including common column also.
Syntax
• SELECT *
FROM table1 INNER JOIN table2 ON
table1.Column_Name = table2.Column_Name;
SELECT *
FROM Student S INNER JOIN Student_Marks M ON
S.Roll_No = M.Roll_No;
Outer Join
• It is used to return all the rows from one table and
the matching rows from the other table.
• If there is no match, NULL values are returned for
columns from the table without a match.
• It is used to deal with missing information.
Syntax:
SELECT column_name(s)
FROM table1 OUTER JOIN table2
ON table1.column_name = table2.column_name;
Left outer join:
• Left outer join contains the set of tuples of all
combinations in R and S that are equal on their
common attribute names.
• In the left outer join, tuples in R have no
matching tuples in S.
• It is denoted by ⟕.
• Example: Using the above EMPLOYEE table and
FACT_WORKERS table
• EMPLOYEE ⟕ FACT_WORKERS
EMPLOYEE ⟖ FACT_WORKERS
Data Definition Language
• Create: Syntax: CREATE table table_name
(
Column1 datatype (size),
column2 datatype (size),

columnN datatype(size)
);
Here table_name is name of the table, column is the name of
column
• CREATE TABLE Customer( CustomerID INT
PRIMARY KEY, CustomerName VARCHAR(50),
LastName VARCHAR(50), Country
VARCHAR(50), Age int(2), Phone int(10) );
Output:

Insert Data into Table
• Insert into Table_name(Column1, Column2,
Column3)
Values (Value1, value2, value3);
• Example: INSERT INTO Customer (CustomerID,
CustomerName, LastName, Country, Age, Phone) VALUES
(1, 'Shubham', 'Thakur', 'India','23','xxxxxxxxxx'), (2,
'Aman ', 'Chopra', 'Australia','21','xxxxxxxxxx'), (3,
'Naveen', 'Tulasi', 'Sri lanka','24','xxxxxxxxxx'), (4, 'Aditya',
'Arpan', 'Austria','21','xxxxxxxxxx'), (5, 'Nishant. Salchichas
S.A.', 'Jain', 'Spain','22','xxxxxxxxxx');
• DROP is used to delete a table.
• DROP TABLE table_name;
• TRUNCATE statement is a Data Definition
Language (DDL) operation that is used to mark
the extent of a table for deallocation (empty
for reuse). The result of this operation quickly
removes all data from a table.
• TRUNCATE TABLE table_name;
Alter command:
• ADD is used to add columns to the existing
table.
• ALTER TABLE table_name ADD
(Columnname_1 datatype, Columnname_2
datatype, …Columnname_n datatype);
• Example:
• Alter table customer add email varchar(255);
• DROP COLUMN is used to drop columns in a
table. Deleting the unwanted columns from
the table.
• Syntax: ALTER TABLE table_name
DROP COLUMN column_name;

• Example: Alter table customer drop column


email;
Comments
• Comments can be written in the following
three formats:
• Single-line comments
• Multi-line comments
• In-line comments
• Single-line comments
Example: SELECT * FROM customers;
-- This is a comment.
Multi-Line Comments
/*
This is a multi-line comment that explains
the purpose of the query below.
*/
SELECT * FROM orders WHERE YEAR(order_date) =
2022;
• In-Line Comments
In line comment ->
SELECT * FROM Students;
SELECT * FROM /* STUDENT_DETAILS;
SELECT * FROM Orders;
SELECT * FROM */ Articles;
Rename
• To rename table.
• Syntax: ALTER TABLE table_name
RENAME TO new_table_name;

• Columns can also be given a new name with the


use of ALTER TABLE.
• Syntax(MySQL, Oracle)
• ALTER TABLE table_name
RENAME COLUMN old_name TO new_name;
Data Manipulation language
• Insert
• Delete
• Update
• select
delete
• DELETE can be used to selectively remove records from a database
table based on certain conditions. This SQL DELETE operation is
important for database size management, data accuracy, and
integrity.
• Syntax:
• DELETE FROM table_name WHERE some_condition;
• Example: DELETE FROM GFG_Employees WHERE NAME = 'Rithvik';
• Delete All of the Records
• To remove all the entries from the table, Query
• DELETE FROM GFG_EMPLOyees;
Or DELETE * FROM GFG_EMPLOyees;
Update
• We can update single columns as well as
multiple columns using the UPDATE statement
as per our requirement.
• Syntax: UPDATE table_name SET column1 =
value1, column2 = value2,…
• Example: UPDATE Customer SET
CustomerName = 'Nitin' WHERE Age = 22;
Select
• The SELECT Statement in SQL is used to retrieve or fetch data.
We can fetch either the entire table or according to some
specified rules. The data returned is stored in a result table.
• To fetch any column in the table.
• Syntax:
• SELECT column1,column2 FROM table_name
• To fetch the entire table or all the fields in the table:
• Syntax:
• SELECT * FROM table_name;
• Suppose we want to see table values with
specific conditions then Where Clause is used
with select statement.
• Query:
• SELECT CustomerName FROM Customer
where Age = '21';
Data control language
• Grant
• Revoke
• Grant: To given privileges to a user account,
the GRANT statement is used.
Syntax:
• GRANT privileges_names ON object TO user;
• REVOKE privileges ON object FROM user;
Transaction Control Language
• This command is used to save all the
transactions in the DB.
• Syntax:
• COMMIT;
• For Example,
• UPDATE Student SET DOB=’2005-03-27’
WHERE Stu_Name=’Joey’;
• COMMIT;
• ROLLBACK Command:
• The “rollback” term refers to the method of undoing
changes. Thus, this command could only be used in
order to reverse transactions that occurred since
the last ROLLBACK or COMMIT command. All the
modifications must be cancelled in case any SQL
grouped statements produce a certain error.
• Syntax:
• ROLLBACK;
• SAVEPOINT Command:
• It is used to roll back a certain transaction to a
certain point rather than the entire
transaction.
• Syntax:
• SAVEPOINT Name_of_Savepoint;
Example: Savepoint s1;
Foreign key

CREATE TABLE Orders (


OrderID int NOT NULL PRIMARY KEY,
OrderNumber int NOT NULL,
PersonID int FOREIGN KEY REFERENCES Persons(PersonID)
Normalization
• Normalization is the process of organizing the data
in the database.
• Normalization is used to minimize the redundancy
from a relation or set of relations. It is also used to
eliminate undesirable characteristics like Insertion,
Update, and Deletion Anomalies.
• Normalization divides the larger table into smaller
and links them using relationships.
• The normal form is used to reduce redundancy from
the database table.
• Data modification anomalies can be
categorized into three types:
• Insertion Anomaly: Insertion Anomaly refers to
when one cannot insert a new tuple into a
relationship due to lack of data.
• Deletion Anomaly: The delete anomaly refers
to the situation where the deletion of data
results in the unintended loss of some other
important data.
• Updation Anomaly: The update anomaly is
when an update of a single data value requires
multiple rows of data to be updated.
1NF
• A relation will be 1NF if it contains an atomic
value.
• It states that an attribute of a table cannot
hold multiple values. It must hold only single-
valued attribute.
2NF
• To be in second normal form, a relation must be in
first normal form and relation must not contain
any partial dependency. A relation is in 2NF if it
has No Partial Dependency, i.e., no non-prime
attribute (attributes which are not part of any
candidate key) is dependent on any proper subset
of any candidate key of the table. Partial
Dependency – If the proper subset of candidate
key determines non-prime attribute, it is called
partial dependency.
3NF
• It is in the second normal form. A relation is in
3NF if at least one of the following conditions
holds in every non-trivial function dependency
X –> Y.
• X is a super key.
• Y is a prime attribute (each element of Y is part
of some candidate key).
• If A->B and B->C are two FDs then A->C is called
transitive dependency.
STUDENT (STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE,
STUD_AGE)
STATE_COUNTRY (STATE, COUNTRY)
BCNF
• BCNF is the advance version of 3NF. It is
stricter than 3NF.
• A table is in BCNF if every functional
dependency X → Y, X is the super key of the
table.
4 NF
th

• For a dependency A -> B, if for a single value


of A, multiple values of B exist, then the table
may have a multi-valued dependency. The
table should have at least 3 attributes and B
and C should be independent for A ->> B
multivalued dependency.
5 NF
th

• Properties
• A relation R is in 5NF if and only if it satisfies
the following conditions:
• 1. R should be already in 4NF.
2. It cannot be further non loss decomposed
(join dependency).
Transaction Management

• Transaction Management is a crucial aspect of


database systems that ensures data
consistency, integrity, and reliability. A
transaction is a sequence of operations (such
as reads and writes) performed on a database
that forms a single logical unit of work. The
ACID properties (Atomicity, Consistency,
Isolation, Durability) are fundamental
principles of transaction management:
• Atomicity: A transaction is atomic, meaning that it either completes
successfully and commits all its changes to the database or fails and
leaves the database unchanged. There are no partial or incomplete
transactions.
• Consistency: Transactions preserve the consistency of the database
by ensuring that it transitions from one consistent state to another
consistent state. In other words, transactions maintain data integrity
and adhere to all integrity constraints.
• Isolation: Transactions execute in isolation from each other, meaning
that the intermediate state of one transaction is not visible to other
transactions until it is committed. This prevents interference and
ensures that transactions produce consistent results.
• Durability: Once a transaction is committed, its changes are
permanently saved to the database and are not lost, even in the
event of a system failure. This ensures that committed transactions
survive system crashes and maintain data durability.

You might also like