You are on page 1of 30

09MBA083

DATABASE MANAGEMENT SYSTEM

DATABASE:
A database is a logically coherent collection of data with some inherent meaning,
representing some aspect of real world and which is designed, built and populated
with data for a specific purpose.

DBMS:
It is a collection of programs that enables user to create and maintain a database.
In other words it is general-purpose software that provides the users with the
processes of defining, constructing and manipulating the database for various
applications.

DATABASE SYSTEM:
The database and DBMS software together is called as Database system.

THE FOLLOWING ARE EXAMPLES OF DATABASE APPLICATIONS:

 computerized library systems


 automated teller machines
 flight reservation systems
 Computerized parts inventory systems.

Let us consider a simple example about a university database for maintaining


information concerning students, courses, and grades in a university
environment. The database is organized as five files:

 The STUDENT file stores data on each student


 The COURSE file stores data on each course
 The SECTION file stores data on each section of a course
 The GRADE_REPORT file stores the grades that students receive in the
various sections they have completed, and
 The PREREQUISITE file stores the prerequisites of each course.

1
09MBA083

2
09MBA083

COMPONENTS OF DBMS

 DBMS Engine accepts logical request from the various other DBMS
subsystems, converts them into physical equivalent, and actually
accesses the database and data dictionary as they exist on a storage
device.

 Data Definition Subsystem helps user to create and maintain the data
dictionary and define the structure of the files in a database.

 Data Manipulation Subsystem helps user to add, change, and delete


information in a database and query it for valuable information. Software
tools within the data manipulation subsystem are most often the primary
interface between user and the information contained in a database. It
allows user to specify its logical information requirements.

 Application Generation Subsystem contains facilities to help users to


develop transactions-intensive applications. It usually requires that user
perform a detailed series of tasks to process a transaction. It facilities
easy-to-use data entry screens, programming languages, and interfaces.

 Data Administration Subsystem helps users to manage the overall


database environment by providing facilities for backup and recovery,
security management, query optimization, concurrency control, and
change management.

ADVANTAGES OF DATABASE MANAGEMENT SYSTEM

Warehouse of Information
The database management systems are warehouses of information, where
large amount of data can be stored. The common examples in commercial
applications are inventory data, personnel data, etc.

Systematic Storage
The data is stored in the form of tables. The tables consists of rows and

3
09MBA083

columns. The primary and secondary key help to eliminate data


redundancy, enabling systematic storage of data.

No Language Dependence
The database management systems are not language dependent. Therefore,
they can be used with various languages and on various platforms.

Data Security
Data is the most important asset. Therefore, there is a need for data
security. Database management systems help to keep the data secured.

Data Consistency
Data consistency ensures a consistent view of data to every user. It includes
the accuracy, validity and integrity of related data. The data in the database
must satisfy certain consistency constraints, for example, the age of a
candidate appearing for an exam should be of number datatype and in the
range of 20-25. When the database is updated, these constraints are
checked by the database systems.

DISADVANTAGES:

Centralization: That is use of the same program at a time by many users


sometimes lead to loss of some data.

High cost of software.

technical expertise are required

Power dependency.
security issues

4
09MBA083

ORACLE

The Oracle Database (commonly referred to as Oracle RDBMS or


simply as Oracle) is a relational database management system
(RDBMS) produced and marketed by Oracle Corporation. As of
2009, Oracle remains a major presence in database computing.

Oracle9i Database provides efficient, reliable, secure data


management for high-end applications such as high-volume on-line
transaction processing (OLTP) environments, query-intensive data
warehouses, and demanding Internet applications. Oracle also
offers several additional optional database products that enhance
the capabilities of Oracle9i Database for specific application
requirements.

5
09MBA083

CLIENT SERVER ARCHITECTURE

The client-server characteristic describes the relationship of


cooperating programs in an application. The server component
provides a function or service to one or many clients, which initiate
requests for such services.

Functions such as email exchange, web access and database access,


are built on the client-server model. For example, a web browser is a
client program running on a user's computer that may access
information stored on a web server on the Internet. Users accessing
banking services from their computer use a web browser client to send
a request to a web server at a bank. That program may in turn
forward the request to its own database client program that sends a
request to a database server at another bank computer to retrieve the
account information. The balance is returned to the bank database
client, which in turn serves it back to the web browser client
displaying the results to the user.

The client-server model has become one of the central ideas of network
computing. Many business applications being written today use the
client-server model. So do the Internet's main application protocols,
such as HTTP, SMTP, Telnet, and DNS. In marketing, the term has
been used to distinguish distributed computing by smaller dispersed
computers from the "monolithic" centralized computing of mainframe
computers. But this distinction has largely disappeared as
mainframes and their applications have also turned to the client-
server model and become part of network computing.

6
09MBA083

TYPES OF CLIENT-SERVER ARCHITECTURE:

(1) 2-TIER ARCHITECTURE

2-tier architecture is used to describe client/server systems where the client


requests resources and the server responds directly to the request, using its own
resources. This means that the server does not call on another application in
order to provide part of the service.

7
09MBA083

(2) 3-TIER ARCHITECTURE

In 3-tier architecture, there is an intermediary level, meaning the architecture is


generally split up between:

1. A client, i.e. the computer, which requests the resources, equipped with a user
interface (usually a web browser) for presentation purposes
2. The application server (also called middleware), whose task it is to provide the
requested resources, but by calling on another server
3. The data server, which provides the application server with the data it requires.

8
09MBA083

(3) MULTI-TIERED ARCHITECTURE

In 3-tier architecture, each server (tier 2 and 3) performs a specialized task (a


service). A server can therefore use services from other servers in order to provide
its own service. As a result, 3-tier architecture is potentially an n-tiered
architecture.

ADVANTAGES:

 In most cases, client-server architecture enables the roles and


responsibilities of a computing system to be distributed among several
independent computers that are known to each other only through a
network.

 All data is stored on the servers, which generally have far greater security
controls than most clients.

 Since data storage is centralized, updates to that data are far easier to
administer.

9
09MBA083

 It functions with multiple different clients of different capabilities.

DISADVANTAGES:

 As the number of simultaneous client requests to a given server increases,


the server can become overloaded.
 The client-server paradigm lacks the robustness of a good P2P network.

10
09MBA083

STRUCTURED QUERY LANGUAGE (SQL)


SQL is a database computer language designed for managing data in relational
database management systems (RDBMS), and originally based upon relational
algebra.

SQL commands can be combined with database commands to define and access
data from a database.

THERE ARE TWO TYPES OF SQL:

(a) Interactive SQL: In this form of SQL we enter a command, it is executed


and we can get the output.

(b) Embedded SQL: This consists of SQL commands put inside of programs
that are written in other language such as FORTRAN, Pascal, COBOL, C
which can make the programs more powerful and efficient.

ADVANTAGES OF SQL:

1. The language while being simple and easy to learn can cope with
complex situations.

2. SQL enables end users and system personnel to deal with a number of
database management systems where it is available.

3. Applications written in SQL can be easily ported across systems.

4. SQL as a language is independent of the way it is implemented


internally. A query returns the same result regardless of whether
optimizing has been done with indexes or not.

5. As the language has a sound theoretical base, there is no ambiguity


about the way a query will interpret the data and produce the results.

11
09MBA083

COMPONENTS OF SQL

DATA DEFINITION LANGUAGE (DDL):

The Data Definition Language (DDL) is used to create and destroy databases and
database objects. These commands will primarily be used by database
administrators during the setup and removal phases of a database project. DDL
commands are:

 CREATE TABLE

 CREATE VIEW

 ALTER TABLE

 DROP TABLE

DATA MANIPULATION LANGUAGE (DML):

DML is used to manipulate data such as to insert, modify, delete or query the data
in the database.DML commands are:

 INSERT

 DELETE

 UPDATE

 SELECT

DATA CONTROL LANGUAGE (DCL):

DCL is used to grant and revoke authorization for database access, auditing the
database use and dealing with transactions. There are many ways that a database
can become corrupted. DCL commands are:

 COMMIT

12
09MBA083

 ROLLBACK

 GRANT

 REVOKE

DATA TYPES IN SQL

(A) CHARACTER STRING DATATYPES

(I) FIXED-LENGTH CHARACTERS


Constant characters, those strings that always have the
same length are stored using fixed length data type.
The standard is:

CHARACTER (n)
Or CHAR (n)
Where n is the number of characters.

(II) VARIABLE CHARACTERS


SQL supports the use of varying- length strings, strings
whose length is not constant for all data. The standard is:

CHARACTER VARYING (n)


Or CHAR VARYING (n)
Or VARCHAR (n)

Where n is the number of characters. It is used for non-


constant character strings to save database space.

(III) BIT STRING


There are two types of bit string:

(a) Fixed length bit string: standard is


BIT (n)
It represents a fixed length string of exactly n bits.

13
09MBA083

(b) Varying length bit string: standard is


BIT VARYING (n)
It represents a varying length string of maximum n bits.

(B) NUMERIC DATA TYPES

(I) INTEGER NUMBERS


An integer is a numeric value that does not contain a
decimal. Standard is:
INTEGER
Or INT
The standard for the small integer is
SMALL INT
(II) FLOATING POINT OR REAL NUMBERS
A floating point number is a numeric value that must
contain a decimal point- standard is
FLOAT
Or REAL
To increase the precision, we can use the double
precision floating point numbers. Standard is:
DOUBLE PRECISION

(III) FORMATTED NUMBERS


Formatted numbers can be declared by using the
following standards:
DECIMAL (n, m)
Or DEC (n, m)
Or Numeric (n, m)

Where n is the precision. The precision is the total length


of the numeric value m is the scale. the scale is the
number of digits to the right of the decimal point.

(IV) A common numeric data type in SQL implementation is


NUMBER
EX: NUMBER (5)
This example restricts the maximum value to 99999.

(C) DATES AND TIME DATATYPES

(I) Date can be declared by using the standard


DATE

14
09MBA083

The format of date is


YYYY-MM-DD

(II) Time can be declared by using the standard


TIME
The format of TIME is
HH: MM: SS

SQL COMMANDS
DDL COMMANDS:

(a) CREATE TABLE

Create table command is used to define (create) a table. Syntax of CREATE


TABLE command is

CREATE TABLE <table name>

(<column specification>, <column specification>….);


Where <table name> gives the table name and <column specification>
includes:
 Column name
 Data type
 Length of column, if any
 Constraints, if applicable

EXAMPLE:

SQL> create table records


2 (rollno number(10),
3 name varchar2(20),
4 address varchar2(30),
5 dob date not null,
6 gender varchar2(1));

Table created.
This will create the “record” table with five columns, namely, ROLL NO.,

15
09MBA083

NAME, ADDRESS, DOB AND GENDER.

SQL> desc records;

Name Null? Type


------------------------------- -------- ----
ROLLNO NUMBER(10)
NAME VARCHAR2(20)
ADDRESS VARCHAR2(30)
DOB NOT NULL DATE
GENDER VARCHAR2(1)

(b) ALTER TABLE

This command is used to add columns to tables or modify column of existing


tables. These commands are of the form

ALTER TABLE<table name>ADD <column specification>

Or

ALTER TABLE <table name>


MODIFY <column name>
<new details for the column>
EXAMPLE:

ALTER TABLE RECORDS


ADD (AGE INT);

This will add one column i.e. age in RECORDS table.

(c) DROP TABLE

Tables may be destroyed with the SQL command DROP TABLE, WHICH IS OF
THE FORM:

DROP TABLE<table name>

EXAMPLE:
DROP TABLE RECORDS

16
09MBA083

This will delete the table RECORDS.

DML COMMANDS:

(a) INSERT COMMAND

For inserting data into the tables, SQL has the INSERT command which is of
the form

INSERT INTO <table name>


[<Column names>]
VALUES (<values>)
An insert is done for a row at a time. If the column names are not specifies,
the values are mapped onto the columns in the order as defined in the
CREATE TABLE of the table

EXAMPLE:

INSERT INTO RECORDS (values (1,'kanika','delhi','11-april-


1988','f');

This command will insert the values into the specified columns only.

SQL> insert into records


values(1,'kanika','delhi','11-april-1988','f');

1 row created.

SQL> insert into records

17
09MBA083

values(2,'atul','delhi','14-october-1990','m');

1 row created.

SQL> insert into records


values(3,'naina','mumbai','11-april-1989','f');

1 row created.

SQL> insert into records


Values (4,'hiten','mumbai','05-march-1975','m');

1 row created.

SQL> insert into records values (5,'sahil','joshi


road','03-january-1987','m');

1 row created

SQL> select * from records;

ROLLNO NAME ADDRESS DOB

--------- -------------------- ------------------------------ ---------


-
1 kanika Delhi 11-APR-88

2 atul Delhi 14-OCT-90

3 naina Mumbai 11-APR-89

4 hiten Mumbai 05-MAR-75

5 sahil joshi road 03-JAN-87

(b) UPDATE COMMAND

To modify data values within values within one or more columns for one or
more rows of a table.
SQL has a command called update. It is of the form
UPDATE<table name>
SET <column name> = <value expression>
[, <column name> = <value expression>

18
09MBA083

………
]
[WHERE <condition>]

The columns whose value have to be updated and the expressions to derive
these values are included in the SET clause. The rows to be updated are those
that meet the condition (s) in the WHERE clause.

EXAMPLE:

UPDATE RECORDS SET ADDRESS = CALCUTTA


WHERE ROLL NO. = ‘01’;

This command will change the address of the student whose roll no. is 01.

(c) DELETE COMMAND

Rows of a table may be deleted using a DELETE command. It is of the form:

DELETE FROM <table name>


[WHERE <condition(s)>]

This command deletes rows from the table specified. If the WHERE clause is given;
only rows meeting the condition (s) are deleted. Otherwise, all rows are deleted.

EXAMPLE:

DELETE FROM RECORDS


WHERE ROLL NO. = ‘02’;

This command will delete the student row whose roll no. is 02.

(d) SELECT COMMAND

Querying on the database is done using the SQL command SELECT. The
SELECT command has with it several clauses that may be used.
It can be in the form:

SELECT <column list>


FROM <table name>
Here it would select the specified columns from all rows of the table given as
<table name>

19
09MBA083

EXAMPLE:
SELECT ROLL NO., NAME, ADDRESS
FROM RECORDS;

In this example SELECT command will display all the rows from the
RECORDS table.

The selection could be made for specific rows which meet some condition,
having a SELECT of the form

SELECT <column list>


FROM <table name>
WHERE <condition(s)>

For example:

SELECT * from records where name='kanika';


This will display the result of the student named “kanika”.

SQL> select address from records;

ADDRESS

------------------------------

Delhi

Delhi

Mumbai

Mumbai

Joshi road

SQL> select * from records where name='kanika';

ROLLNO NAME ADDRESS DOB

20
09MBA083

--------- -------------------- ------------------------------ ---------


-
1 kanika delhi 11-APR-88

OPERATORS IN SQL

There are various types of operators in SQL:

ARITHMETIC OPERATORS
+ , -, *, /

RELATIONAL OPERATORS
=, <>, <, <=, >, >=

CONJUNCTION OPERATORS
These are used to combine the conditions.
AND, OR

LOGICAL OPERATORS

Logical operators in SQL are:

OPERATORS MEANING
IS NULL compare a value with a null value

BETWEEN search for a values that are within a


set of value
IN Compare a value to a list of value that
has been specified.
LIKE Compare a value to similar values
using wildcard operators.
EXISTS Search for the presence of a row in a
specified table that meets certain
criteria.

21
09MBA083

UNIQUE search every row of a specified table for


uniqueness(no duplicate)
ALL compare a value to all values in
another value set
ALL compare a value to any applicable
value in the list according to the
condition

AGGREGATE FUNCTIONS OR SUMMARY FUNCTIONS

An aggregate function is used to provide summarization information for a SQL


statement, such as counts, totals and averages. Some aggregate functions are:

FUNCTION MEANING
COUNT ( ) Count rows or values of a column that do
not contain a null value.
COUNT (*) Count all the rows of a table including
duplicates.
SUM ( ) Return a total or sum on the values of a
numeric column for a group of rows.
AVG ( ) Find average for a group of rows.

MAX ( ) Return the maximum value for the values


of a column in a group of rows.
MIN ( ) Return the minimum value for the values
of a column in a group of rows.

22
09MBA083

SQL QUERIES

A query is an inquiry into the database using the SELECT statement.

TABLE “RECORDS” DETAILS:

Roll no. Name Address Dob Gender


01 Kanika Delhi 11-april-88 f
02 Atul Delhi 14-oct-90 m
03 Naina Mumbai 11-april-89 f
04 Hiten Mumbai 05-mar-75 m
05 Sahil Joshi road 03-jan-87 m

TABLE “EMPLOYEE” DETAILS:

Emp no. E name Job Mgr Hire date Sal


Deptt no.
7369 Smith Clerk 7902 17-dec-80 800
20
7499 Allen Salesman 7698 20-feb-81 1600
30
7521 Ward Salesman 7698 22-feb-81 1250
30
7566 Jones Manager 7839 02-apr-81 2975
20
7654 Martin salesman 7698 28-SEP-81 1250
30
7698 Blake manager 7839 01-MAY-81 2850
30
7782 Clark Manager 7839 09-JUN-81 2450
10
7788 Scott Analyst 7566 19-APR-87 3000

23
09MBA083

20
7839 King President 17-NOV-81 5000
10
7844 Turner Salesman 7698 08-SEP-81 1500
30
7876 Adams Clerk 7788 23-MAY-87 1100
20
7900 James Clerk 7698 03-DEC-81 950
30
7902 Ford Analyst 7566 03-DEC-81 3000
20
7034 Miller Clerk 7782 23-jan-82 1300
10

1. GET FULL DETAILS OF ALL STUDENTS FROM TABLE RECORDS

SQL> select * from records;


THE OUTPUT OF THIS QUERY WOULD BE:
G ROLLNO NAME ADDRESS DOB

--------- -------------------- ------------------------------ ---------


-
F 1 kanika delhi 11-APR-88

M 2 atul delhi 14-OCT-90

F 3 naina mumbai 11-APR-89

M 4 hiten mumbai 05-MAR-75

M 5 sahil joshi road 03-JAN-87

2. GET THE NAMES OF ALL THE STUDENTS

SQL> select name from records;


OUTPUT:

NAME

--------------------

24
09MBA083

kanika

atul

naina

hiten

sahil

3. GET DETAILS OF STUDENT WHOSE NAME IS KANIKA

SQL> select * from records where name='kanika';


OUTPUT:

G ROLLNO NAME ADDRESS DOB

--------- -------------------- ------------------------------ ---------

F 1 kanika delhi 11-APR-88

4. GET NAME OF THE EMPLOYEE WHOSE SALARY IN (1500,2200)


SQL> select ename from EMPLOYEE where sal in (1500,2200);
OUTPUT:
ENAME

----------

TURNER
ALLEN

5. GET THE NAME, DEPTTNO. , HIREDATE OF EMPLOYEE IN ASCENDING


DEPTT.NO.
SQL>select ENAME, DEPTNO, HIREDATE from EMPLOYEE
order by DEPTNO [asc];
OUTPUT:

ENAME DEPTNO HIREDATE

---------- ----------------------- ---------

25
09MBA083

FORD 10 03-DEC-81

SMITH 20 17-DEC-80

BLAKE 30 01-MAY-81

WARD 30 22-FEB-81

ALLEN 30 20-FEB-81

6. ADDING COLUMN INTO THE TABLE “RECORDS”


SQL> alter table records
2 add marks number (12);

Table altered.

OUTPUT:

SQL> desc records;


Name Null? Type
------------------------------- -------- ----
ROLLNO NUMBER(10)
NAME VARCHAR2(20)
ADDRESS VARCHAR2(30)
DOB NOT NULL DATE
GENDER VARCHAR2(1)
MARKS NUMBER(12)

7. GET THE SUM OF SALARY OF ALL EMPLOYEES


SQL> select sum(sal) from EMPLOYEE;

OUTPUT:

SUM (SAL)

---------

29025

8. SELECTING MAXIMUM, MINIMUM & CALCULATING AVERAGE SALARY


FROM THE TABLE EMPLOYEE.

26
09MBA083

SQL> select max(sal),min(sal),avg(sal) from EMPLOYEE;

OUTPUT:

MAX (SAL) MIN (SAL) AVG (SAL)

--------- --------- ---------


5000 800 2073.2143

9. GET THE EMPLOYEE NAME WHOSE HIREDATE BETWEEN 02-APR-81 &


08-SEP-81
SQL>select ENAME from EMPLOYEE
where HIREDATE between ’02-APR-81’ and ’08-SEP-81’;

OUTPUT:

ENAME

----------

Jones

Blake

Clark

Turner

10. GET THE JOB & SALARY OF EMPLOYEES ,NAMES BEGIN WITH A

SQL>select job, salary from EMPLOYEE


Where ENAME LIKE ‘%A%’;

OUTPUT:

27
09MBA083

Job Salary

---------- ----------

Salesman 1600

Clerk 1100

11. GET THE EMPLOYEES WHOSE SALARY GREATER THAN 2500 AND
DEPTT NO. LESS THAN 30
SQL>Select * from EMPLOYEE
Where salary >2500 AND Deptt no. < 30;

OUTPUT:

EMPNO ENAME JOB MGR HIREDATE SAL


DEPTNO
--------- ---------- --------- --------- --------- ---------
---------

7566 JONES MANAGER 7839 02-APR-81 2975

20

7788 SCOTT ANALYST 7566 19-APR-87 3000

20

7839 KING PRESIDENT 17-NOV-81 5000

10

7902 FORD ANALYST 7566 03-DEC-81 3000

20

28
09MBA083

12. GET THE DEPARTMENT NO. OF ALL THE EMPLOYEES WITH NO


DUPLICATION.
SQL> SELECT DISTINCT DEPT NO FROM EMPLOYEE;

OUTPUT:

DEPTNO
---------
20
30

SQL JOIN

SUPPLIERS

SUPP_ID SUPP_NAME
------------- --------------

100 AMIT
101 RAVI
102 JOHN
103 PARK
104 SMITH

ORDERS

ORD_ID SUPP_ID ORD_DATE


--------- ----------- --------------

125 100 2009/03/12


126 101 2009/05/15

SQL> SELECT SUPPLIER.SUPP_ID, SUPPLIER.SUPP_NAME, ORDERS.ORD_DATE

29
09MBA083

2FROM SUPPLIERS, ORDERS

3WHERE SUPPLIER.SUPP_ID=ORDERS.SUPP_ID;

OUTPUT:

SUPP_ID SUPP_NAME ORD_DATE


--------- --------- ---------
100 AMIT 2009/03/12
101 RAVI 2009/03/15

30

You might also like