0% found this document useful (0 votes)
16 views31 pages

Book Summary

A database is a structured collection of inter-related data managed by a Database Management System (DBMS), which allows for efficient data retrieval, insertion, and deletion. DBMS provides various functionalities such as data definition, updating, retrieval, and user administration while ensuring data security and consistency. There are different types of databases, including centralized, distributed, and relational databases, each with its own advantages and disadvantages.

Uploaded by

Mustapha Kaoje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views31 pages

Book Summary

A database is a structured collection of inter-related data managed by a Database Management System (DBMS), which allows for efficient data retrieval, insertion, and deletion. DBMS provides various functionalities such as data definition, updating, retrieval, and user administration while ensuring data security and consistency. There are different types of databases, including centralized, distributed, and relational databases, each with its own advantages and disadvantages.

Uploaded by

Mustapha Kaoje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

What is Database

The database is a collection of inter-related data which is used to retrieve, insert


and delete the data efficiently. It is also used to organize the data in the form of a
table, schema, views, and reports, etc. For example: The college Database
organizes the data about the admin, staff, students and faculty etc. Using the
database, you can easily retrieve, insert, and delete the information.

Database Management System

 Database management system is a software which is used to manage the


database. For example: MYSQL, Oracle etc are a very popular commercial
database which is used in different applications.
 DBMS provides an interface to perform various operations like database
creation, storing data in it, updating data, creating a table in the database and
a lot more.
 It provides protection and security to the database. In the case of multiple
users, it also maintains data consistency.

DBMS allows users the following tasks:

 Data Definition: It is used for creation, modification, and removal of


definition that defines the organization of data in the database.
 Data Updation: It is used for the insertion, modification, and deletion of the
actual data in the database.
 Data Retrieval: It is used to retrieve the data from the database which can
be used by applications for various purposes.
 User Administration: It is used for registering and monitoring users,
maintain data integrity, enforcing data security, dealing with concurrency
control, monitoring performance and recovering information corrupted by
unexpected failure.

Characteristics of DBMS

 It uses a digital repository established on a server to store and manage the


information.
 It can provide a clear and logical view of the process that manipulates data.
 DBMS contains automatic backup and recovery procedures.
 It contains ACID properties which maintain data in a healthy state in case of
failure.
 It can reduce the complex relationship between data.
 It is used to support manipulation and processing of data.
 It is used to provide security of data.
 It can view the database from different viewpoints according to the
requirements of the user.

Advantages of DBMS

 Controls database redundancy: It can control data redundancy because it


stores all the data in one single database file and that recorded data is placed
in the database.
 Data sharing: In DBMS, the authorized users of an organization can share
the data among multiple users.
 Easily Maintenance: It can be easily maintainable due to the centralized
nature of the database system.
 Reduce time: It reduces development time and maintenance need.
 Backup: It provides backup and recovery subsystems which create
automatic backup of data from hardware and Software failures and restores
the data if required.
 multiple user interface: It provides different types of user interfaces like
graphical user interfaces, application program interfaces

Disadvantages of DBMS

 Cost of Hardware and Software: It requires a high speed of data processor


and large memory size to run DBMS software.
 Size: It occupies a large space of disks and large memory to run them
efficiently.
 Complexity: Database system creates additional complexity and
requirements.
 Higher impact of failure: Failure is highly impacted the database because
in most of the organization, all the data stored in a single database and if the
database is damaged due to electric failure or database corruption then the
data may be lost forever.
Types of Databases

There are various types of databases used for storing different varieties of data:

1) Centralized Database

It is the type of database that stores data at a centralized database system. It


comforts the users to access the stored data from different locations through
several applications. These applications contain the authentication process to let
users access data securely. An example of a Centralized database can be Central
Library that carries a central database of each library in a college/university.

Advantages of Centralized Database

 It has decreased the risk of data management, i.e., manipulation of data will
not affect the core data.
 Data consistency is maintained as it manages data in a central repository.
 It provides better data quality, which enables organizations to establish data
standards.
 It is less costly because fewer vendors are required to handle the data sets.
Disadvantages of Centralized Database

 The size of the centralized database is large, which increases the response
time for fetching the data.
 It is not easy to update such an extensive database system.
 If any server failure occurs, entire data will be lost, which could be a huge
loss.

2) Distributed Database

Unlike a centralized database system, in distributed systems, data is distributed


among different database systems of an organization. These database systems are
connected via communication links. Such links help the end-users to access the
data easily. Examples of the Distributed database are Apache Cassandra, HBase,
Ignite, etc.

We can further divide a distributed database system into:

 Homogeneous DDB: Those database systems which execute on the same


operating system and use the same application process and carry the same
hardware devices.
 Heterogeneous DDB: Those database systems which execute on different
operating systems under different application procedures, and carries
different hardware devices.

3) Relational Database

This database is based on the relational data model, which stores data in the form
of rows(tuple) and columns(attributes), and together forms a table(relation). A
relational database uses SQL for storing, manipulating, as well as maintaining the
data. E.F. Codd invented the database in 1970. Each table in the database carries a
key that makes the data unique from others. Examples of Relational databases are
MySQL, Microsoft SQL Server, Oracle, etc.

Properties of Relational Database

There are following four commonly known properties of a relational model known as ACID
properties, where:

A means Atomicity: This ensures the data operation will complete either with success or with
failure. It follows the 'all or nothing' strategy. For example, a transaction will either be
committed or will abort.

C means Consistency: If we perform any operation over the data, its value before and after the
operation should be preserved. For example, the account balance before and after the transaction
should be correct, i.e., it should remain conserved.

I means Isolation: There can be concurrent users for accessing data at the same time from the
database. Thus, isolation between the data should remain isolated. For example, when multiple
transactions occur at the same time, one transaction effects should not be visible to the other
transactions in the database.

D means Durability: It ensures that once it completes the operation and commits the data, data
changes should remain permanent.

DBMS Architecture

 The DBMS design depends upon its architecture. The basic client/server
architecture is used to deal with a large number of PCs, web servers,
database servers and other components that are connected with networks.
 The client/server architecture consists of many PCs and a workstation which
are connected via the network.
 DBMS architecture depends upon how users are connected to the database to
get their request done.

Types of DBMS Architecture

Database architecture can be seen as a single tier or multi-tier. But logically,


database architecture is of two types like: 2-tier architecture and 3-tier architecture.

1-Tier Architecture

 In this architecture, the database is directly available to the user. It means the
user can directly sit on the DBMS and uses it.
 Any changes done here will directly be done on the database itself. It doesn't
provide a handy tool for end users.
 The 1-Tier architecture is used for development of the local application,
where programmers can directly communicate with the database for the
quick response.
2-Tier Architecture

 The 2-Tier architecture is same as basic client-server. In the two-tier


architecture, applications on the client end can directly communicate with
the database at the server side. For this interaction, API's like: ODBC, JDBC
are used.
 The user interfaces and application programs are run on the client-side.
 The server side is responsible to provide the functionalities like: query
processing and transaction management.
 To communicate with the DBMS, client-side application establishes a
connection with the server side.

3-Tier Architecture

 The 3-Tier architecture contains another layer between the client and server.
In this architecture, client can't directly communicate with the server.
 The application on the client-end interacts with an application server which
further communicates with the database system.
 End user has no idea about the existence of the database beyond the
application server. The database also has no idea about any other user
beyond the application.
 The 3-Tier architecture is used in case of large web application.

Three schema Architecture

 The three schema architecture is also called ANSI/SPARC architecture or


three-level architecture.
 This framework is used to describe the structure of a specific database
system.
 The three schema architecture is also used to separate the user applications
and physical database.
 The three schema architecture contains three-levels. It breaks the database
down into three different categories.

The three-schema architecture is as follows:

In the above diagram:

 It shows the DBMS architecture.


 Mapping is used to transform the request and response between various
database levels of architecture.
 Mapping is not good for small DBMS because it takes more time.
 In External / Conceptual mapping, it is necessary to transform the request
from external level to conceptual schema.
 In Conceptual / Internal mapping, DBMS transform the request from the
conceptual to internal level.

Objectives of Three schema Architecture

The main objective of three level architecture is to enable multiple users to access
the same data with a personalized view while storing the underlying data only
once. Thus it separates the user's view from the physical structure of the database.
This separation is desirable for the following reasons:

 Different users need different views of the same data.


 The approach in which a particular user needs to see the data may change
over time.
 The users of the database should not worry about the physical
implementation and internal workings of the database such as data
compression and encryption techniques, hashing, optimization of the internal
structures etc.
 All users should be able to access the same data according to their
requirements.
 DBA should be able to change the conceptual structure of the database
without affecting the user's
 Internal structure of the database should be unaffected by changes to
physical aspects of the storage.

Mapping between Views


The three levels of DBMS architecture don't exist independently of each other.
There must be correspondence between the three levels i.e. how they actually
correspond with each other. DBMS is responsible for correspondence between the
three types of schema. This correspondence is called Mapping.

There are basically two types of mapping in the database architecture:

 Conceptual/ Internal Mapping


 External / Conceptual Mapping

Conceptual/ Internal Mapping

The Conceptual/ Internal Mapping lies between the conceptual level and the
internal level. Its role is to define the correspondence between the records and
fields of the conceptual level and files and data structures of the internal level.

External/ Conceptual Mapping

The external/Conceptual Mapping lies between the external level and the
Conceptual level. Its role is to define the correspondence between a particular
external and the conceptual view.

Data Models

Data Model is the modeling 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:
1) Relational Data Model: This type of model designs the data in the form of
rows and columns within a table. Thus, a relational model uses tables for
representing data and in-between relationships. Tables are also called relations.
This model was initially described by Edgar F. Codd, in 1969. The relational data
model is the widely used model which is primarily used by commercial data
processing applications.

2) Entity-Relationship Data Model: An ER model is the logical representation of


data as objects and relationships among them. These objects are known as entities,
and relationship is an association among these entities. This model was designed
by Peter Chen and published in 1976 papers. It was widely used in database
designing. A set of attributes describe the entities. For example, student_name,
student_id describes the 'student' entity. A set of the same type of entities is known
as an 'Entity set', and the set of the same type of relationships is known as
'relationship set'.
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.

Data model Schema and Instance

 The data which is stored in the database at a particular moment of time is


called an instance of the database.
 The overall design of a database is called schema.
 A database schema is the skeleton structure of the database. It represents the
logical view of the entire database.
 A schema contains schema objects like table, foreign key, primary key,
views, columns, data types, stored procedure, etc.
 A database schema can be represented by using the visual diagram. That
diagram shows the database objects and relationship with each other.
 A database schema is designed by the database designers to help
programmers whose software will interact with the database. The process of
database creation is called data modeling.
A schema diagram can display only some aspects of a schema like the name of
record type, data type, and constraints. Other aspects can't be specified through the
schema diagram. For example, the given figure neither show the data type of each
data item nor the relationship among various files.

In the database, actual data changes quite frequently. For example, in the given
figure, the database changes whenever we add a new grade or add a student. The
data at a particular moment of time is called the instance of the database.
Database Language

 A DBMS has appropriate languages and interfaces to express database


queries and updates.
 Database languages can be used to read, store and update the data in the
database.

Types of Database Language

1. Data Definition Language

 DDL stands for Data Definition Language. It is used to define database


structure or pattern.
 It is used to create schema, tables, indexes, constraints, etc. in the database.
 Using the DDL statements, you can create the skeleton of the database.
 Data definition language is used to store the information of metadata like the
number of tables and schemas, their names, indexes, columns in each table,
constraints, etc.
Here are some tasks that come under DDL:

 Create: It is used to create objects in the database.


 Alter: It is used to alter the structure of the database.
 Drop: It is used to delete objects from the database.
 Truncate: It is used to remove all records from a table.
 Rename: It is used to rename an object.
 Comment: It is used to comment on the data dictionary.

These commands are used to update the database schema that's why they come
under Data definition language.

2. Data Manipulation Language

DML stands for Data Manipulation Language. It is used for accessing and
manipulating data in a database. It handles user requests.

Here are some tasks that come under DML:

 Select: It is used to retrieve data from a database.


 Insert: It is used to insert data into a table.
 Update: It is used to update existing data within a table.
 Delete: It is used to delete all records from a table.
 Merge: It performs UPSERT operation, i.e., insert or update operations.
 Call: It is used to call a structured query language or a Java subprogram.
 Explain Plan: It has the parameter of explaining data.
 Lock Table: It controls concurrency.
3. Data Control Language

 DCL stands for Data Control Language. It is used to retrieve the stored or
saved data.
 The DCL execution is transactional. It also has rollback parameters.

(But in Oracle database, the execution of data control language does not
have the feature of rolling back.)

Here are some tasks that come under DCL:

 Grant: It is used to give user access privileges to a database.


 Revoke: It is used to take back permissions from the user.

There are the following operations which have the authorization of Revoke:

CONNECT, INSERT, USAGE, EXECUTE, DELETE, UPDATE and SELECT.

4. Transaction Control Language

TCL is used to run the changes made by the DML statement. TCL can be grouped
into a logical transaction.

Here are some tasks that come under TCL:

 Commit: It is used to save the transaction on the database.


 Rollback: It is used to restore the database to original since the last Commit.

SQL

 SQL stands for Structured Query Language. It is used for storing and
managing data in relational database management system (RDMS).
 It is a standard language for Relational Database System. It enables a user to
create, read, update and delete relational databases and tables.
 All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server
use SQL as their standard database language.
 SQL allows users to query the database in a number of ways, using English-
like statements.

Rules:

SQL follows the following rules:

 Structure query language is not case sensitive. Generally, keywords of SQL


are written in uppercase.
 Statements of SQL are dependent on text lines. We can use a single SQL
statement on one or multiple text line.
 Using the SQL statements, you can perform most of the actions in a
database.
 SQL depends on tuple relational calculus and relational algebra.

SQL process:

 When an SQL command is executing for any RDBMS, then the system
figure out the best way to carry out the request and the SQL engine
determines that how to interpret the task.
 In the process, various components are included. These components can be
optimization Engine, Query engine, Query dispatcher, classic, etc.
 All the non-SQL queries are handled by the classic query engine, but SQL
query engine won't handle logical files.
Characteristics of SQL

 SQL is easy to learn.


 SQL is used to access data from relational database management systems.
 SQL can execute queries against the database.
 SQL is used to describe the data.
 SQL is used to define the data in the database and manipulate it when needed.
 SQL is used to create and drop the database and table.
 SQL is used to create a view, stored procedure, function in a database.
 SQL allows users to set permissions on tables, procedures, and views.
Advantages of SQL

There are the following advantages of SQL:

High speed

Using the SQL queries, the user can quickly and efficiently retrieve a large amount
of records from a database.

No coding needed

In the standard SQL, it is very easy to manage the database system. It doesn't
require a substantial amount of code to manage the database system.

Well defined standards

Long established are used by the SQL databases that are being used by ISO and
ANSI.

Portability

SQL can be used in laptop, PCs, server and even some mobile phones.

Interactive language

SQL is a domain language used to communicate with the database. It is also used
to receive answers to the complex questions in seconds.

Multiple data view

Using the SQL language, the users can make different views of the database
structure.
SQL Datatype

 SQL Datatype is used to define the values that a column can contain.
 Every column is required to have a name and data type in the database table.

Datatype of SQL:

1. Binary Datatypes

There are Three types of binary Datatypes which are given below:

Data Type Description


It has a maximum length of 8000 bytes. It contains fixed-length binary
binary
data.
It has a maximum length of 8000 bytes. It contains variable-length
varbinary
binary data.
It has a maximum length of 2,147,483,647 bytes. It contains variable-
image length binary data.

2. Approximate Numeric Datatype :

The subtypes are given below:


Data
From To Description
type
-1.79E + 1.79E + It is used to specify a floating-point value e.g.
float
308 308 6.2, 2.9 etc.
It specifies a single precision floating point
real -3.40e + 38 3.40E + 38
number
3. Exact Numeric Datatype

The subtypes are given below:

Data
Description
type
int It is used to specify an integer value.
smallint It is used to specify small integer value.
bit It has the number of bits to store.
decimal It specifies a numeric value that can have a decimal number.
numeric It is used to specify a numeric value.
Data
Description
type
It has a maximum length of 8000 characters. It contains Fixed-length
char
non-unicode characters.
It has a maximum length of 8000 characters. It contains variable-length
varchar
non-unicode characters.
It has a maximum length of 2,147,483,647 characters. It contains
text
variable-length non-unicode characters.

5. Date and time Datatypes

The subtypes are given below:

Datatype Description
date It is used to store the year, month, and days value.
time It is used to store the hour, minute, and second values.
timestamp It stores the year, month, day, hour, minute, and the second value.

SQL Commands

 SQL commands are instructions. It is used to communicate with the


database. It is also used to perform specific tasks, functions, and queries of
data.
 SQL can perform various tasks like create a table, add data to tables, drop
the table, modify the table, set permission for users.

Types of SQL Commands

There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
1. Data Definition Language (DDL)

 DDL changes the structure of the table like creating a table, deleting a table,
altering a table, etc.
 All the command of DDL are auto-committed that means it permanently
save all the changes in the database.

Here are some commands that come under DDL:

 CREATE
 ALTER
 DROP
 TRUNCATE

a. CREATE It is used to create a new table in the database.


Syntax:

CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);

Example:

CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB DAT


E);

b. DROP: It is used to delete both the structure and record stored in the table.

Example

DROP TABLE EMPLOYEE;

c. ALTER: It is used to alter the structure of the database. This change could be
either to modify the characteristics of an existing attribute or probably to add a new
attribute.

Syntax:

To add a new column in the table

1. ALTER TABLE table_name ADD column_name COLUMN-definition;

To modify existing column in the table:

1. ALTER TABLE table_name MODIFY(column_definitions....);

EXAMPLE

ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));

ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));

d. TRUNCATE: It is used to delete all the rows from the table and free the space
containing the table.

Syntax:

TRUNCATE TABLE table_name;


Example:

TRUNCATE TABLE EMPLOYEE;

2. Data Manipulation Language

 DML commands are used to modify the database. It is responsible for all
form of changes in the database.
 The command of DML is not auto-committed that means it can't
permanently save all the changes in the database. They can be rollback.

Here are some commands that come under DML:

 INSERT
 UPDATE
 DELETE

a. INSERT: The INSERT statement is a SQL query. It is used to insert data into
the row of a table.

Syntax:

INSERT INTO TABLE_NAME

(col1, col2, col3,.... col N)

VALUES (value1, value2, value3, .... valueN);

Or

INSERT INTO TABLE_NAME

VALUES (value1, value2, value3, .... valueN);

For example:

1. INSERT INTO javatpoint (Author, Subject) VALUES ("SAD", "DBMS");

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


the table.

Syntax:
1. UPDATE table_name SET [column_name1= value1,...column_nameN = val
ueN] [WHERE CONDITION]

For example:

1. UPDATE students
2. SET User_Name = 'Abduljalal'
3. WHERE Student_Id = '3'

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

Syntax:

1. DELETE FROM table_name [WHERE condition];

For example:

DELETE FROM Attendance

WHERE Author="Abdul";

3. Data Control Language

DCL commands are used to grant and take back authority from any database user.

Here are some commands that come under DCL:

 Grant
 Revoke

a. Grant: It is used to give user access privileges to a database.

Example

GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTH


ER_USER;

b. Revoke: It is used to take back permissions from the user.

Example

REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;


4. Transaction Control Language

TCL commands can only use with DML commands like INSERT, DELETE and
UPDATE only.

These operations are automatically committed in the database that's why they
cannot be used while creating tables or dropping them.

Here are some commands that come under TCL:

 COMMIT
 ROLLBACK
 SAVEPOINT

a. Commit: Commit command is used to save all the transactions to the database.

Syntax:

1. COMMIT;

Example:

1. DELETE FROM CUSTOMERS


2. WHERE AGE = 25;
3. COMMIT;

b. Rollback: Rollback command is used to undo transactions that have not already
been saved to the database.

Syntax:

1. ROLLBACK;

Example:

1. DELETE FROM CUSTOMERS


2. WHERE AGE = 25;
3. ROLLBACK;

c. SAVEPOINT: It is used to roll the transaction back to a certain point without


rolling back the entire transaction.
Syntax:

1. SAVEPOINT SAVEPOINT_NAME;

5. Data Query Language

DQL is used to fetch the data from the database.

It uses only one command:

 SELECT

a. SELECT: This is the same as the projection operation of relational algebra. It is


used to select the attribute based on the condition described by WHERE clause.

Syntax:

1. SELECT expressions
2. FROM TABLES
3. WHERE conditions;

For example:

1. SELECT emp_name
2. FROM employee
3. WHERE age > 20;

You might also like