Unit 4 Dbms
Unit 4 Dbms
DATA
DATABASE:
o 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.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 2
COMPUTERS FUNDAMETALS
o 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.
o It provides protection and security to the database. In the case of multiple users, it also
maintains data consistency.
o Data Definition: It is used for creation, modification, and removal of definition that defines the
organization of data in the database.
o Data UpdatioAn: It is used for the insertion, modification, and deletion of the actual data in the
database.
o Data Retrieval: It is used to retrieve the data from the database which can be used by
applications for various purposes.
o 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.
TYPES OF DATABASES:
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 user’s 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.
2) Distributed Database
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 3
COMPUTERS FUNDAMETALS
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.
o Homogeneous DDB: Those database systems which execute on the same operating
system and use the same application process and carry the same hardware devices.
o 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.
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.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 4
COMPUTERS FUNDAMETALS
4) NoSQL Database
● Non-SQL/Not Only SQL is a type of database that is used for storing a wide range of data
sets. It is not a relational database as it stores data not only in tabular form but in several
different ways. It came into existence when the demand for building modern
applications increased. Thus, NoSQL presented a wide variety of database technologies
in response to the demands. We can further divide a NoSQL database into the following
four types:
5) Cloud Database
A type of database where data is stored in a virtual environment and executes over the
cloud computing platform. It provides users with various cloud computing services
(SaaS, PaaS, IaaS, etc.) for accessing the database. There are numerous cloud platforms,
but the best options are:
6) Object-oriented Databases
● The type of database that uses the object-based data model approach for storing data in
the database system. The data is represented and stored as objects which are similar to
the objects used in the object-oriented programming language.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 5
COMPUTERS FUNDAMETALS
● File based systems were an early attempt to computerize the manual system. It is also
called a traditional based approach in which a decentralized approach was taken where
each department stored and controlled its own data with the help of a data processing
specialist.
● The main role of a data processing specialist was to create the necessary computer file
structures, and also manage the data within structures and design some application
programs that create reports based on file data.
Consider an example of a student's file system. The student file will contain information
regarding the student (i.e. roll no, student name, course etc.). Similarly, we have a subject file
that contains information about the subject and the result file which contains the information
regarding the result.
Some fields are duplicated in more than one file, which leads to data redundancy. So to
overcome this problem, we need to create a centralized system, i.e. DBMS approach.
DBMS:
A database approach is a well-organized collection of data that are related in a meaningful way
which can be accessed by different users but stored only once in a system. The various
operations performed by the DBMS system are: Insertion, deletion, selection, sorting etc.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 6
COMPUTERS FUNDAMETALS
Sharing of data Due to the centralized approach, Data is distributed in many files, and it
data sharing is easy. may be of different formats, so it isn't
easy to share data.
Data Abstraction DBMS gives an abstract view of The file system provides the detail of
data that hides the details. the data representation and storage
of data.
Security and DBMS provides a good protection It isn't easy to protect a file under the
Protection mechanism. file system.
Recovery DBMS provides a crash recovery The file system doesn't have a crash
Mechanism mechanism, i.e., DBMS protects mechanism, i.e., if the system crashes
the user from system failure. while entering some data, then the
content of the file will be lost.
Manipulation DBMS contains a wide variety of The file system can't efficiently store
Techniques sophisticated techniques to store and retrieve the data.
and retrieve the data.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 7
COMPUTERS FUNDAMETALS
Concurrency DBMS takes care of Concurrent In the File system, concurrent access
Problems access of data using some form of has many problems like redirecting
locking. the file while deleting some
information or updating some
information.
Where to use Database approach used in large File system approach used in large
systems which interrelate many systems which interrelate many files.
files.
Cost The database system is expensive The file system approach is cheaper to
to design. design.
Data Redundancy Due to the centralization of the In this, the files and application
and database, the problems of data programs are created by different
Inconsistency redundancy and inconsistency are programmers so that there exists a lot
controlled. of duplication of data which may lead
to inconsistency.
Structure The database structure is complex The file system approach has a simple
to design. structure.
Data In this system, Data Independence In the File system approach, there
Independence exists, and it can be of two types. exists no Data Independence.
o Logical Data Independence
o Physical Data Independence
Data Models In the database approach, 3 types In the file system approach, there is
of data models exist: no concept of data models exists.
o Hierarchal data models
o Network data models
o Relational data models
DATABASE APPLICATIONS:
Now days Databases are widely used in the application development world. Here are
some examples of using DBMS applications:
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 8
COMPUTERS FUNDAMETALS
◦ Sales of the Items: For customer, Items details, and purchase details.
◦ Manufacturing Industries: For management of the supply chain management and for
tracking production of items in manufacturing units, inventories of items in warehouses of
the factories and stores, and orders for items.
Online Vendors: For online sales order tracking, generation of recommendation item lists,
and maintenance of online product evaluations.
◦ Banking: For customer information such as account_no, Name of the Customers, Address
, Saving Accounts, Fixed Accounts, Current Accounts, Loan Accounts, and banking
transactions.
◦ Credit Card Management System: Credit cards using in online purchase, offline purchase,
generation of monthly statements, Credit Limits every data manage in this system.
◦ Finance Management: For storing information about holdings the shares, bonds,
debentures, sales, and purchases of financial instruments and also for storing real-time
marketing fluctuating data to enable online trading by customers and automated online
trading by the firm.
DATABASE USERS
Database users are categorized based up on their interaction with the data base.
These are seven types of data base users in DBMS.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 9
COMPUTERS FUNDAMETALS
For examples, Railway’s ticket booking users are naive users. Clerks in any bank is a naive
user because they don’t have any DBMS knowledge but they still use the database and
perform their given task.
3. System Analyst :
System Analyst is a user who analyzes the requirements of parametric end users. They check
whether all the requirements of end users are satisfied.
4. Sophisticated Users :
Sophisticated users can be engineers, scientists, business analyst, who are familiar with the
database. They can develop their own data base applications according to their requirement.
They don’t write the program code but they interact the data base by writing SQL queries
directly through the query processor.
6. Application Program :
Application Program are the back end programmers who writes the code for the application
programs.They are the computer professionals. These programs could be written in
Programming languages such as Visual Basic, Developer, C, FORTRAN, COBOL etc.
they access the data base they require the new information, for example, Middle or higher
level manager.
INTRODUCTION TO SQL:
o SQL stands for Structured Query Language. It is used for storing and managing data in
relational database management system (RDMS).
o It is a standard language for Relational Database System. It enables a user to create,
read, update and delete relational databases and tables.
o All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as their
standard database language.
o SQL allows users to query the database in a number of ways, using English-like
statements.
Rules:
SQL follows the following rules:
o Structure query language is not case sensitive. Generally, keywords of SQL are written in
uppercase.
o Statements of SQL are dependent on text lines. We can use a single SQL statement on
one or multiple text line.
o Using the SQL statements, you can perform most of the actions in a database.
o SQL depends on tuple relational calculus and relational algebra.
SQL process:
o 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.
o In the process, various components are included. These components can be
optimization Engine, Query engine, Query dispatcher, classic, etc.
o All the non-SQL queries are handled by the classic query engine, but SQL query engine
won't handle logical files.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 11
COMPUTERS FUNDAMETALS
Characteristics of SQL
o SQL is easy to learn.
o SQL is used to access data from relational database management systems.
o SQL can execute queries against the database.
o SQL is used to describe the data.
o SQL is used to define the data in the database and manipulate it when needed.
o SQL is used to create and drop the database and table.
o SQL is used to create a view, stored procedure, function in a database.
o SQL allows users to set permissions on tables, procedures, and views.
DATA TYPES:
BASIC TYPES
● The SQL standard supports a variety of built-in types, including:
• char(n): A fixed-length character string with user-specified length n. The full
form, character, can be used instead.
• varchar(n): A variable-length character string with user-specified maximum
length n. The full form, character varying, is equivalent.
• int: An integer (a finite subset of the integers that ismachine dependent). The full
form, integer, is equivalent.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 12
COMPUTERS FUNDAMETALS
SQL Commands
o 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.
o SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.
o There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 13
COMPUTERS FUNDAMETALS
o CREATE
o ALTER
o DROP
o TRUNCATE
b. DROP: It is used to delete both the structure and record stored in the table.
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.
EXAMPLE
d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the
table.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 14
COMPUTERS FUNDAMETALS
o NSERT
o UPDATE
o DELETE
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax:
Or
For example:
b. UPDATE: This command is used to update or modify the value of a column in the table.
Syntax:
UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE
CONDITION]
For example:
UPDATE students
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 15
COMPUTERS FUNDAMETALS
For example:
o Grant
o Revoke
These operations are automatically committed in the database that's why they cannot be used
while creating tables or dropping them.
o COMMIT
o ROLLBACK
o SAVEPOINT
a. Commit: Commit command is used to save all the transactions to the database.
Syntax: COMMIT;
Example:
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 16
COMPUTERS FUNDAMETALS
Syntax: ROLLBACK;
Example:
o 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:
SELECT expressions
FROM TABLES
WHERE conditions;
For example:
SELECT emp_name
FROM employee
WHERE age > 20;
Constraints are the rules that we can apply on the type of data in a table. That is, we can specify
the limit on the type of data that can be stored in a particular column in a table using
constraints.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 17
COMPUTERS FUNDAMETALS
● NOT NULL: This constraint tells that we cannot store a null value in a column. That is, if a
column is specified as NOT NULL then we will not be able to store null in this particular
column any more.
● UNIQUE: This constraint when specified with a column, tells that all the values in the column
must be unique. That is, the values in any row of a column must not be repeated.
● PRIMARY KEY: A primary key is a field which can uniquely identify each row in a table. And
this constraint is used to specify a field in a table as primary key.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 18
COMPUTERS FUNDAMETALS
● FOREIGN KEY: A Foreign key is a field which can uniquely identify each row in a another
table. And this constraint is used to specify a field as Foreign key.
● CHECK: This constraint helps to validate the values of a column to meet a particular
condition. That is, it helps to ensure that the value stored in a column meets a specific
condition.
CREATE TABLE Student
(
ID int(6) NOT NULL,
NAME varchar(10) NOT NULL,
AGE int NOT NULL CHECK (AGE >= 18)
);
● DEFAULT: This constraint specifies a default value for the column when no value is specified
by the user.
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 19