Unit 1
Unit 1
1. Database
The database is the collection of data that is organized and stored. It can consist of several
elements, such as:
Tables: The primary storage structure in a relational database, consisting of rows and columns.
Records/Rows: Individual entries in a table, each representing a single data item or entity.
Fields/Columns: Attributes or properties of the data, defining the type of data stored in each
record.
Indexes: Structures that improve the speed of data retrieval operations on a table.
The DBMS is software that provides tools and services for creating, managing, and manipulating
databases. Key functions of a DBMS include:
Data Definition Language (DDL): Used to define database structures, such as tables and indexes.
Common DDL commands include CREATE, ALTER, and DROP.
Data Manipulation Language (DML): Used for querying and modifying data. Common DML
commands include SELECT, INSERT, UPDATE, and DELETE.
Data Control Language (DCL): Used to control access to data. Common DCL commands include
GRANT and REVOKE.
Transaction Management: Ensures data integrity and consistency through mechanisms like
commit and rollback.
Concurrency Control: Manages simultaneous data access to prevent conflicts and ensure data
consistency.
Backup and Recovery: Provides mechanisms to back up data and recover it in case of failure.
3. Database Schema
The schema defines the logical structure of the database, including tables, fields, relationships,
and constraints. Components of the schema include:
4. Query Processor
The query processor interprets and executes database queries. Key components include:
5. Storage Manager
The storage manager handles the storage, retrieval, and updating of data in the database. It
includes:
6. Metadata
Data Dictionary: Contains information about database objects, such as tables, columns, indexes,
and users.
Catalog: A system catalog that holds schema information and other metadata.
7. User Interface
The user interface allows users to interact with the database. It can include:
Command Line Interface (CLI): Allows users to enter SQL commands directly.
Graphical User Interface (GUI): Provides a more user-friendly way to interact with the database,
often with visual tools for query building and data management.
Application Programming Interface (API): Enables applications to interact programmatically
with the database.
8. Database Applications
Applications are programs that interact with the database to perform specific tasks. Examples
include:
Enterprise Resource Planning (ERP) Systems: Integrate various business processes and
functions.
Customer Relationship Management (CRM) Systems: Manage customer data and interactions.
Content Management Systems (CMS): Manage digital content and facilitate collaboration.
9. Security Management
Security management ensures that only authorized users have access to the database and its data.
Components include:
Conclusion
These components work together to form a cohesive database system that allows for the efficient
storage, retrieval, and management of data. Understanding these components is essential for
designing, using, and maintaining effective database systems.
Disadvantages of DBMS
There are many advantages and disadvantages of DBMS (Database
Management System). The disadvantages of DBMS are explained
below.
1. Increased Cost:
These are different types of costs:
File Manager: It manages the file space and the data structure used to
represent information in the database.
Database Schemas
Nowadays data is one of the most important things in the business world,
every business captures its customers’ data to understand their behavior, in
the world of the internet, data is growing like crazy, so businesses need
more advanced database solutions, by which they can maintain the database
systems and whenever they need data to solve business problems, they can
easily get what data they want without any problem. To fulfill this condition,
there is a requirement for the database schema in the picture.
What is Schema?
The Skeleton of the database is created by the attributes and this
skeleton is named Schema.
Schema mentions the logical constraints like table, primary key, etc.
The schema does not represent the data type of the attributes.
Details of a Customer
Schema of Customer
Database Schema
A database schema is a logical representation of data that shows how
the data in a database should be stored logically. It shows how the data
is organized and the relationship between the tables.
Database schema contains table, field, views and relation between
different keys like primary key, foreign key.
Data are stored in the form of files which is unstructured in nature which
makes accessing the data difficult. Thus to resolve the issue the data are
organized in structured way with the help of database schema.
Database schema provides the organization of data and the relationship
between the stored data.
Database schema defines a set of guidelines that control the database
along with that it provides information about the way of accessing and
modifying the data.
Types of Database Schemas
There are 3 types of database schema:
Physical Database Schema
A Physical schema defines, how the data or information is stored
physically in the storage systems in the form of files & indices. This is the
actual code or syntax needed to create the structure of a database, we
can say that when we design a database at a physical level, it’s called
physical schema.
The Database administrator chooses where and how to store the data in
the different blocks of storage.
Logical Database Schema
A logical database schema defines all the logical constraints that need to
be applied to the stored data, and also describes tables, views, entity
relationships, and integrity constraints.
The Logical schema describes how the data is stored in the form of tables
& how the attributes of a table are connected.
Using ER modelling the relationship between the components of the data
is maintained.
In logical schema different integrity constraints are defined in order to
maintain the quality of insertion and update the data.
View Database Schema
It is a view level design which is able to define the interaction between
end-user and database.
User is able to interact with the database with the help of the interface
without knowing much about the stored mechanism of data in database.
Three Layer Schema Design
Hierarchical Model
Data is arranged using parent-child relationships and a tree-like structure in
the Hierarchical Database Model. Because each record consists of several
children and one parent, it can be used to illustrate one-to-many
relationships in diagrams such as organizational charts. Although obvious, it
might not be as adaptable in complicated partnerships.
Designing Hierarchical Model
Network Model
The network model and the hierarchical model are quite similar with an
important difference that is related to data relationships. The network model
allows many-to-many relationships whereas hierarchical models allow one-
to-many relationships.
Relational Model
The relational model is mainly used for relational databases, where the data
is stored as relations of the table. This relational model schema is better for
object-oriented programming.
Designing Relational Model
Star Schema
Star schema is better for storing and analyzing large amounts of data. It has
a fact table at its center & multiple dimension tables connected to it just like a
star, where the fact table contains the numerical data that run business
processes and the dimension table contains data related to dimensions such
as product, time, people, etc. or we can say, this table contains the
description of the fact table. The star schema allows us to structure the data
of RDBMS.
Physical schema contains the Logical schema does not contain any
attributes and their data types. attributes or data types.
Conclusion
The Structure of the database is referred to as the Schema, and it
represents logical restrictions like Table and Key, among other things.
Three Schema Architecture was developed to prevent the user from direct
access to the database.
Since the information that is saved in the database is subject to frequent
change, Instance is a representation of a data at a specific time.
It mainly concerns how the data is stored It mainly concerns about changes to the
in the system. structure or data definition.
To make changes at the physical level we To make changes at the logical level, we
generally do not require changes at the need to make changes at the application
application program level. level.
It tells about the internal schema. It tells about the conceptual schema.
There may or may not be a need for Whenever the logical structure of
changes to be made at the internal level to the database has to be changed, the changes
improve the structure. made at the logical level are important.
Conclusion
The data independence property of the database is an expected
property that relies on separating the logical and physical aspects of
storing and accessing data. This means that it is easy to make
structural modifications to the database without affecting the
applications that use it. This is a situation that impacts the capacity
of the organization to remain adaptable in the dynamic business
environment, as well as making sure that the technological
advancements within the organization are interoperable over a long
period of time.
output
create table
Alter
It is one the command in DDL which is used for change or alter the structure
of the database or table. I already created students table with some columns
you can see in the above image. Now by using Alter command I add new
column that weight to the students table.
Syntax:
ALTER TABLE Students ADD column_name;
Example:
Alter command
Drop
This Drop command is used for delete objects from the database. In this
example I drop the students table
Syntax:
DROP Table Table_name;
Example:
drop
Truncate
Truncate command is used for remove all records from a table. Now I
remove rows from the Student table.
Syntax:
TRUNCATE TABLE table_name;
Example:
truncate
Rename
It is used to rename the object in database. Now I rename the table
from students to ClassMembers. Below I provide the example for better
understanding.
Syntax:
ALTER TABLE Old_Table_Name RENAME TO New_Table_Name;
Example:
Rename
Comment
It is used for comment on the data dictionary. We have two different
comments namely Single line comment and Multi-line comments.
Single Line
-- This is a single-line comment
Multi-line comment
/*
This is a
multi-line comment
*/
DCL (Data Control Language)
The DCL stands for Data Control Language means these commands are
used to retrieve the saved data from database. And one more thing is the
DCL execution is Transactional that means It have roll back parameters. we
have two tasks under the Data Control Language below I listed them
Grant It is used for give user access to the database
Revoke It is used for to take back the access or permissions from the
user
Now I will explain these commands with proper examples for better
understanding
Grant
Basically The grant command is used for provide database access to the
new user. Here I create one user then I give the access to the database.
Syntax:
GRANT privileges
ON object
TO user_or_role [WITH GRANT OPTION];
Example:
GRANT SELECT, INSERT ON students TO user;
Revoke
The Revoke command is used to to take back database access from the
user. Now I provide the example in the below
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. Below I listed those commands for your reference
Select It is used for select data from the Table based on the requirements
Insert It is sued for Inserting data into existing table
Update It is used for update data in the Table based on the requirement
Delete It is used for delete data from the Table
Merge It is used for upsert operations
Call It is used for call a structured query language or Java sub program
Lock Table It have ability to control the concurrency
Now I will explain each command with proper example for better
understanding the concept.
Select
The Select command is used for select required data based on conditions
from a existing Table. Here I select all data from the ClassMembers Table.
Syntax:
SELECT * FROM Table_Name
Example:
Select Command
Insert
The Insert command is used for inserting new data into Table. Now I insert a
new data into ClassMembers Table. Below I provide the example.
Syntax:
INSERT INTO Table_Name (Column 1, Column 2, Column 3, Column 4)
VALUES (Value 1, Value 2,Value 3, Value 4);
Example:
Insert command
Update
The Update command is used for update information In the Table. Now I will
update name John Doe to Roman in the ClassMemebers Table. Below I
provide that Example you can update any row or columns data.
Syntax:
UPDATE Table_Name SET Name = 'New_Value' WHERE Name =
'Ola_Value';
Example:
Update
Delete:
The Delete command is used for delete data from the Table. Here I delete
Student Id with 2 from the ClassMembers. Below I provide the Example for
your reference.
Syntax:
DELETE FROM Table_Name WHERE Column = Value;
Example:
Delete Command
Merge
The Merge command is used for perform upsert operation means It inserts
rows that doesn’t exist and updates rows that do.
Example:
MERGE INTO target_table AS target
USING source_table AS source
ON (target.id = source.id)
WHEN MATCHED THEN
UPDATE SET target.name = source.name
WHEN NOT MATCHED THEN
INSERT (id, name) VALUES (source.id, source.name);
CALL
The Call command is used for call the user defined functions
Example:
CALL user_defined_function(parameter 1, parameter 2);
LOCK TABLE
The lock table command is used for lock the table for preventing access from
the others for same Table
Syntax:
LOCK TABLE your_table IN EXCLUSIVE MODE;
Example:
LOCK TABLE ClassMembers IN EXCLUSIVE MODE;
TCL ( Transaction Control Language )
The TCL full form is Transaction Control Language commands are used to
run the changes made by the DML commands And one more thing is TCL
can be grouped into a logical transaction. And We have two different
commands in this category below I listed them for reference.
Commit It is used for save the transaction on the Database. And these
very useful in banking sectors.
Rollback It is used for restore the database to original state from last
commit. This command also plays an important role in Banking Sectors.
Now I will explain these two commands for your reference. And I provide
proper examples below I provide those example
Commit
The Commit command is used for 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 a new data into
Table then I commit It.
Syntax:
Database Operation
Commit
Example:
commit
ROLLBACK
Rollback command is used for restore the database to original state from last
commit. Here I provide the example and in this I already commit the you can
see in the above, Now I delete one row from the Table then again rollback
the previous database state.
Syntax:
ROLLBACK;
Example:
rollback
Conclusion
In this article I will explained Database Languages In Database which are
used for different purposes. We have DDL, DCL, DML, TCL these are
different categories. The DDL language is used for used for define the
database internal structure and Pattern of the Database. And the DCL
commands are used to control the data from the user means It can provide
control on the Database, Table and Data. The DML commands are used to
manipulate the Data in Table like Inserting, updating, deleting of the Data
finally the TCL commands are used to save and restore the previous state of
Database.
a. Hierarchical DBMS:
b. Network DBMS:
f. NoSQL DBMS:
Structure: Non-relational and can handle various data formats.
Types:
o Document Stores: MongoDB, CouchDB.
o Key-Value Stores: Redis, DynamoDB.
o Column Stores: Cassandra, HBase.
o Graph Databases: Neo4j, Amazon Neptune.
Use Case: Big data, real-time web applications, social networks.
2. Classification by Usage
a. Single-User DBMS:
b. Multi-User DBMS:
4. Classification by Architecture
a. Centralized DBMS:
b. Distributed DBMS:
c. Client-Server DBMS:
d. Cloud DBMS:
a. In-Memory DBMS:
b. Disk-Based DBMS: