Database Notes
Database Notes
Used to manage and organize the files A software to store and retrieve the
stored in the hard disk of the computer user’s data
Redundant data is present No presence of Redundant data
Less complex, does not support More complexity in managing the data,
complicated transactions easier to implement complicated
transactions
4 SURESH DELHI 18
Important Terminologies
•Attribute:
Attributes are the properties that define an entity.
e.g.; ROLL_NO, NAME, ADDRESS
•Relation Schema:
A relation schema defines the structure of the relation and
represents the name of the relation with its attributes. e.g.;
STUDENT (ROLL_NO, NAME, ADDRESS, PHONE, and AGE) is the
relation schema for STUDENT. If a schema has more than 1
relation, it is called Relational Schema.
•Tuple:
Each row in the relation is known as a tuple. The above relation
contains 4 tuples, one of which is shown as:
Types of Entity
There are two types of entity:
1. Strong Entity
A Strong Entity is a type of entity that has a key Attribute. Strong
Entity does not depend on other Entity in the Schema. It has a
primary key, that helps in identifying it uniquely, and it is represented
by a rectangle.
2. Weak Entity
•An Entity type has a key attribute that uniquely
identifies each entity in the entity set. But some entity
type exists for which key attributes can’t be defined.
These are called Weak Entity types .
For Example, A company may store the information of
dependents (Parents, Children, Spouse) of an Employee.
But the dependents can’t exist without the employee.
•So Dependent will be a Weak Entity Type and Employee
will be Identifying Entity type for Dependent, which
means it is Strong Entity Type .
•A weak entity type is represented by a Double
Rectangle.
What is 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.
Types of Attributes
1. Key Attribute
The attribute which uniquely identifies each entity in the
entity set is called 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.
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.
4. Derived Attribute
An attribute that can be derived from other
attributes of the entity type is 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) Object-based Data Model:
An extension of the ER model with notions of
functions, encapsulation, and object identity, as
well. This model supports a rich type system that
includes structured and collection types. Thus, in
1980s, various database systems following the
object-oriented approach were developed. Here,
the objects are nothing but the data carrying its
properties.
4) Semistructured Data Model:
This type of data model is different from the other three
data models (explained above).
The semistructured data model allows the data
specifications at places where the individual data items
of the same type may have different attributes sets.
The Extensible Markup Language, also known as XML, is
widely used for representing the semistructured data.
Although XML was initially designed for including the
markup information to the text document, it gains
importance because of its application in the exchange of
data.
Database Language
Database language refers to the specific types of commands or
instructions used to communicate with a database. It helps users
or applications to create, manage, update, and retrieve data from
a database. database language is like a set of tools that help you
talk to and work with the data stored in a database.
Types of Database Languages in DBMS
1. Data Definition Language
2. Data Manipulation Language
3. Data Control Language
4. Transactional Control Language
1. DDL (Data Definition Language)
The DDL stands for Data Definition Language, Which is used to define
the database's internal structure and Pattern of the Database.
The DDL is used for creating tables, indexes, constraints, and schema
in the Database.
By using DDL statements we can able to create the architecture of the
required database.
Database commands used in DDL
Create: It is used to create objects in the database
Alter: It is used to change or alter the structure of the database
objects
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 the object in the database
Comment: It is used for comments on the data dictionary.
Create Command
It is one of the commands in DDL that is used for creating objects
the database means creating Tables, Users, Triggers, functions, and
other objects. Here I will show how to create a table by
using create command from DDL.
Syntax
CREATE TABLE Students (
column1 INT,
column2 VARCHAR(50),
column3 INT
);
Example:
CREATE TABLE Students(Student_ID INT PRIMARY KEY,NAME
VARCHAR(50),AGE INT);
2.DCL (Data Control Language)
The DCL stands for Data Control Language means these commands
are used to retrieve the saved data from the database. And one
more thing is the DCL execution is Transactional which means It
has rollback parameters.
we have two tasks under the Data Control Language below I listed
them
Grant: It is used to give user access to the database
Revoke: It is used to take back access or permissions from the user
Grant Command
The GRANT command in a Database Management System (DBMS)
is used to provide specific permissions or privileges to users or
roles. This command allows administrators to control access to
database objects, ensuring that only authorized users can perform
certain actions, such as selecting, inserting, updating, or deleting
data.
Syntax
GRANT privileges
ON object
TO user_or_role [WITH GRANT OPTION];
Example
GRANT SELECT, INSERT ON students TO user;
Revoke Command
The REVOKE command in a Database Management System
(DBMS) is used to remove previously granted permissions or
privileges from users or roles. This command is essential for
managing access control, ensuring that users do not have more
privileges than necessary to perform their tasks.
Syntax
REVOKE privileges ON object FROM user_or_role;
Example
REVOKE ALL PRIVILEGES ON students FROM user;
DML (Data Manipulation Language)
The Data Manipulation Language is used to Manipulate the data in
the database by using different commands. In this category we can
able to perform Insert new data into Table, Update existing data in
the Table, Delete Data from the Table, and other functions we can
perform on data by using these DML commands.
Select: It is used to select data from the Table based on the
requirements
Insert: It is used for Inserting data into an existing table
Update: It is used to update data in the Table based on the
requirement
Delete: It is used to delete data from the Table
Merge: It is used for upsert operations
Call: It is used to call a structured query language or Java sub-
program
Lock Table: It can control the concurrency
Select Command
The SELECT command in SQL (Structured Query Language) is used
to retrieve data from one or more tables in a database. It is one of
the most commonly used commands in SQL, allowing users to
specify exactly what data they want to see and how they want it
organized.
Syntax
SELECT * FROM Table_Name
Example:
Select*from students table;
Insert Command
The INSERT command in SQL (Structured Query Language) is used
to add new records or rows to a table in a database. This
command is essential for populating a database with data and can
be used to insert data into all or specific columns of a table.
Syntax
INSERT INTO Table_Name (Column 1, Column 2, Column 3, Column
4) VALUES (Value 1, Value 2,Value 3, Value 4);
Example
INSERT INTO Students
table(STUDENT_ID,NAME,AGE,SEX)VALUES(101,JOHNSON,22,MAL
E);
4. TCL ( Transaction Control Language )
The TCL full form is Transaction Control Language commands are
used to run the changes made by the DML commands one more
thing is TCL can be grouped into a logical transaction. We have two
different commands in this category I listed them for reference.
Commit: It is used to save the transaction on the Database. These
are very useful in the banking sector.
Rollback: It is used to restore the database to its original state
from the last commit. This command also plays an important role
in Banking Sectors.
Commit Command
The Commit command is used to save the transaction in the
database and changes are made by the DML statements. Now I
will provide the example below Here I used ClassMembers Table.
Here I inserted new data into the Table then I committed It.
Syntax
Database Operation
Commit
ROLLBACK Command
The rollback command is used to restore the database to its
original state from the last commit. Here I provide the example
and in this, I already commit what you can see above, Now I delete
one row from the Table and then again roll back the previous
database state.
Syntax
ROLLBACK;
ACID Properties in DBMS
DBMS is the management of data that should remain
integrated when any changes are done in it. It is because
if the integrity of the data is affected, whole data will get
disturbed and corrupted.
Therefore, to maintain the integrity of the data, there are
four properties described in the database management
system, which are known as the ACID properties.
The ACID properties are meant for the transaction that
goes through a different group of tasks, and there we
come to see the role of the ACID properties.
ACID Properties
1) Atomicity
The term atomicity defines that the data remains atomic. It means if
any operation is performed on the data, either it should be
performed or executed completely or should not be executed at all.
It further means that the operation should not break in between or
execute partially. In the case of executing operations on the
transaction, the operation should be completely executed and not
partially.
Example:
Consider transaction from Account A to Account B
If the credit and debit process done successful then Atomicity is
complete
Thus, when the amount loses atomicity, then in the bank systems,
this becomes a huge issue, and so the atomicity is the main focus
in the bank systems.
2) Consistency
The word consistency means that the value should remain
preserved always. In DBMS, the integrity of the data should be
maintained, which means if a change in the database is made, it
should remain preserved always. In the case of transactions, the
integrity of the data is very essential so that the database remains
consistent before and after the transaction. The data should
always be correct.
Example
Consider three accounts A,B and C in which A
debits to B and C, when debit and credit both
become successful then the process is consistent.
3) Isolation
The term 'isolation' means separation. In DBMS, Isolation is the
property of a database where no data should affect the other one and
may occur concurrently. In short, the operation on one database
should begin when the operation on the first database gets complete.
It means if two operations are being performed on two different
databases, they may not affect the value of one another. In the case of
transactions, when two or more transactions occur simultaneously,
the consistency should remain maintained. Any changes that occur in
any particular transaction will not be seen by other transactions until
the change is not committed in the memory.
Example: If two operations are concurrently running on two different
accounts, then the value of both accounts should not get affected. The
value should remain persistent.
As you can see in the below diagram, account A is making T1 and T2
transactions to account B and C, but both are executing independently
without affecting each other. It is known as Isolation.
4) Durability
Durability ensures the permanency of something. In DBMS, the
term durability ensures that the data after the successful
execution of the operation becomes permanent in the database.
The durability of the data should be so perfect that even if the
system fails or leads to a crash, the database still survives.
However, if gets lost, it becomes the responsibility of the
recovery manager for ensuring the durability of the database.
For committing the values, the COMMIT command must be used
every time we make changes.
Therefore, the ACID property of DBMS plays a vital role in
maintaining the consistency and availability of data in the
database.
Thus, it was a precise introduction of ACID properties in DBMS.
We have discussed these properties in the transaction section
also.
THANK YOU