0% found this document useful (0 votes)
38 views19 pages

Unit 4 Dbms

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

Unit 4 Dbms

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

COMPUTERS FUNDAMETALS

DATA

● Data is a collection of a distinct small unit of information. It can be used in a variety of


forms like text, numbers, media, bytes, etc. it can be stored in pieces of paper or
electronic memory, etc.
● Word 'Data' is originated from the word 'datum' that means 'single piece of information.'
It is plural of the word datum.
● In computing, Data is information that can be translated into a form for efficient
movement and processing. Data is interchangeable.

DATABASE:

● A database is a systematic collection of data. They support electronic storage and


manipulation of data. Databases make data management easy.
● Let us discuss a database example: An online telephone directory uses a database to
store data of people, phone numbers, and other contact details. Your electricity service
provider uses a database to manage billing, client-related issues, handle fault data, etc.
● Let us also consider Facebook. It needs to store, manipulate, and present data related to
members, their friends, member activities, messages, advertisements, and a lot more.
We can provide a countless number of examples for the usage of databases.

DATABASE MANAGEMENT SYSTEM (DBMS)

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.

DBMS allows users the following tasks:

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.

Advantages of Centralized Database


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

Disadvantages of Centralized Database


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

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.

We can further divide a distributed database system into:

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.

Advantages of Distributed Database


o Modular development is possible in a distributed database, i.e., the system can be
expanded by including new computers and connecting them to the distributed system.
o One server failure will not affect the entire data set.

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.

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:

a. Key-value storage: It is the simplest type of database storage where it stores


every single item as a key (or attribute name) holding its value, together.
a. Document-oriented Database: A type of database used to store data as
JSON-like document. It helps developers in storing data by using the same
document-model format as used in the application code.
b. Graph Databases: It is used for storing vast amounts of data in a graph-like
structure. Most commonly, social networking websites use the graph database.
c. Wide-column stores: It is similar to the data represented in relational
databases. Here, data is stored in large columns together, instead of storing in
rows.

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:

o Amazon Web Services(AWS)


o Microsoft Azure
o Kamatera

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.

WHY DATABASE –FILE SYSTEM VS DBMS:

BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 5
COMPUTERS FUNDAMETALS

FILE SYSTEM APPROACH:

● 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

In the above figure,

In the above figure, duplication of data is reduced due to centralization of data.

Basis DBMS Approach File System Approach

Meaning DBMS is a collection of data. In The file system is a collection of data.


DBMS, the user is not required to In this system, the user has to write
write the procedures. the procedures for managing the
database.

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

Integrity Integrity Constraints are easy to Integrity Constraints are difficult to


Constraints apply. implement in file system.

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

• Venture System (Such as Super Market Application)

◦ Sales of the Items: For customer, Items details, and purchase details.

◦ Accounting Information’s: For payments activities, receipts information, account


balances data, assets and other accounting information etc.

◦ Human Resources Management: For information about the company or venture


employees number, Name, Address, salaries, payroll taxes, and benefits, and for
generation of paychecks.

◦ 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.

• Financial Institutes and Banking Management System:

◦ 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

1. Database Administrator (DBA) :


Database Administrator (DBA) is a person/team who defines the schema and also controls
the 3 levels of database.
The DBA will then create a new account id and password for the user if he/she need to
access the data base.
DBA is also responsible for providing security to the data base and he allows only the
authorized users to access/modify the data base.
● DBA also monitors the recovery and back up and provide technical support.
● The DBA has a DBA account in the DBMS which called a system or superuser account.
● DBA repairs damage caused due to hardware and/or software failures.

2. Naive / Parametric End Users :


Parametric End Users are the unsophisticated who don’t have any DBMS knowledge but they
frequently use the data base applications in their daily life to get the desired results.

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.

5. Data Base Designers :


Data Base Designers are the users who design the structure of data base which includes
tables, indexes, views, constraints, triggers, stored procedures. He/she controls what data
must be stored and how the data items to be related.

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.

7. Casual Users / Temporary Users :


Casual Users are the users who occasionally use/access the data base but each time when
BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 10
COMPUTERS FUNDAMETALS

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

• smallint: A small integer (a machine-dependent subset of the integer type).


• numeric(p, d):Afixed-point numberwith user-specified precision. The number
consists of p digits (plus a sign), and d of the p digits are to the right of the
decimal point. Thus, numeric(3,1) allows 44.5 to be stored exactly, but neither
444.5 or 0.32 can be stored exactly in a field of this type.
• real, double precision: Floating-point and double-precision floating-point
numbers with machine-dependent precision.
• float(n): A floating-point number, with precision of at least n digits.

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.

Types of SQL Commands

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

1. DATA DEFINITION LANGUAGE (DDL)


o DDL changes the structure of the table like creating a table, deleting a table, altering a
table, etc.
o 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:

o CREATE
o ALTER
o DROP
o 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 DATE);

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

Syntax: DROP TABLE table_name;

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

ALTER TABLE table_name ADD column_name COLUMN-definition;


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.

BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 14
COMPUTERS FUNDAMETALS

Syntax: TRUNCATE TABLE table_name;

Example: TRUNCATE TABLE EMPLOYEE;

2. DATA MANIPULATION LANGUAGE


o DML commands are used to modify the database. It is responsible for all form of
changes in the database.
o 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

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:

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:

INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");

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

SET User_Name = 'Sonoo'


WHERE Student_Id = '3'

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

Syntax: DELETE FROM table_name [WHERE condition];

For example:

DELETE FROM javatpoint


WHERE Author="Sonoo";

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:

o Grant
o Revoke

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

Example GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_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:

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

DELETE FROM CUSTOMERS


WHERE AGE = 25;
COMMIT;
b. Rollback: Rollback command is used to undo transactions that have not already been saved
to the database.

Syntax: ROLLBACK;

Example:

DELETE FROM CUSTOMERS


WHERE AGE = 25;
ROLLBACK;
c. SAVEPOINT: It is used to roll the transaction back to a certain point without rolling back the
entire transaction.

Syntax : SAVEPOINT SAVEPOINT_NAME;

5. Data Query Language


DQL is used to fetch the data from the database.

It uses only one command:

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;

DDL WITH CONSTRAINTS:

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

The available constraints in SQL are:

● 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.

CREATE TABLE Student


(
ID int(6) NOT NULL,
NAME varchar(10) NOT NULL,
ADDRESS varchar(20)
);

● 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.

CREATE TABLE Student


(
ID int(6) NOT NULL UNIQUE,
NAME varchar(10),
ADDRESS varchar(20)
);

● 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.

CREATE TABLE Student


(
ID int(6) NOT NULL UNIQUE,
NAME varchar(10),
ADDRESS varchar(20),
PRIMARY KEY(ID)
);

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.

CREATE TABLE Orders


(
O_ID int NOT NULL,
ORDER_NO int NOT NULL,
C_ID int,
PRIMARY KEY (O_ID),
FOREIGN KEY (C_ID) REFERENCES Customers(C_ID)
)

● 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.

CREATE TABLE Student


(
ID int(6) NOT NULL,
NAME varchar(10) NOT NULL,
AGE int DEFAULT 18
);

BLDEA S. B. S. ARTS, COMMERCE AND SCIENCE COLLEGE FOR WOMEN BCA PROGRAMME PAGE 19

You might also like