0% found this document useful (0 votes)
12 views118 pages

CP4152 DBP Lab Manual (ME)

Data base practices lab manual

Uploaded by

Thasnim Shanu
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)
12 views118 pages

CP4152 DBP Lab Manual (ME)

Data base practices lab manual

Uploaded by

Thasnim Shanu
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/ 118

ROEVER ENGINEERING COLLEGE

ELAMBALUR, PERAMBALUR – 621 220


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

LABORATORY RECORD

Name : ----------------------------------------------------

Reg. No. : ---------------------------------------

Subject : ---------------------------------------

Year/Semester : ---------------------------------------

1
ROEVER ENGINEERING COLLEGE
ELAMBALUR, PERAMBALUR – 621 220.

BONAFIDE CERTIFICATE
Certified that this is the Bonafide record of Practical done in

CP4152- DATABASE PRACTICES LABORATORY by..……..………………………………….

Reg.No: ………….….….......................in I Year / I Semester M.E CSE during the period

June 2022 - December 2022.

STAFF-IN-CHARGE HEAD OF THE DEPARTMENT

Submitted for the University Practical Examinations

Held on………….……

INTERNAL EXAMINER EXTERNAL EXAMIN

2
CONTENTS

EX.
PAGE
DATE NAME OF THE EXPERIMENT NO.
Marks SIGNATURE
NO.

3
EX.NO:1

Date:

DATA DEFINITION COMMANDS, DATA MANIPULATION COMMANDS FOR INSERTING,


DELETING, UPDATING, RETRIEVING TABLES AND TRANSACTION CONTROL STATEMENTS

DATA DEFINITION COMMANDS

AIM:

To create the database and write DDL, DML and TCL Queries to retrieve information from the
database.

ALGORITHM:

1. Start the program

2. Using create command create a table which contain the attribute of employee.

3. Execute various DDL, DML and TCL commands to retrieve information from the database.

4. Stop.

DDL COMMANDS

 CREATE TABLE
 CREATE TABLE ……AS SELECT
 ALTER TABLE………ADD
 ALTER TABLE………MODIFY
 DROP TABLE
 RENAME

1.CREATE TABLE

It is used to create a table

Syntax: Create table tablename (column_name1 data_ type constraints, column_name2 data_
type constraints …)

4
SQL> create table emp(eno number(10),ename varchar2(10),dno number(10),sal number(10),jobid
varchar2(10),mgrid varchar2(10));
Table created

2. CREATE TABLE AS SELECT...


Syntax For Create A from An Existing Table With All Fields
SQL> create table <target table name> select * from <source table name>;

SQL> create table emp1 as select * from emp;


Table created.
SQL> desc emp1
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID VARCHAR2(10)
MGRID VARCHAR2(10)

2.1 Syntax For Create A from An Existing Table With Selected Fields
SQL> create table <traget table name> select empno, ename from <source table name>;
SQL> create table emp2 as select empno, ename from emp;
Table created.
SQL> desc emp2
Name Null? Type
------------------ -------- ----------------------
EMPNO NUMBER (4)
EMPNAME VARCHAR2(10)

3.DESC
This is used to view the structure of the table.
SQL> desc emp;

5
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID VARCHAR2(10)
MGRID VARCHAR2(10)

3.ALTER TABLE

Alter command is used to:


1. Add a new column.
2. Modify the existing column definition.
3. To include or drop integrity constraint.

Syntax: alter table tablename add/modify (attribute datatype(size));

3.1ADD
SQL> alter table emp add(primary key(eno), addr varchar2(10));

Table altered.

SQL> desc emp;

Name Null? Type


----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID VARCHAR2(10)
MGRID VARCHAR2(10)
ADDR VARCHAR2(10)

SQL> alter table emp add(phno number(5));

Table altered.

SQL> desc emp;

6
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID CHAR(20)
MGRID VARCHAR2(10)
ADDR VARCHAR2(10)
PHNO NUMBER(5)

3.2 MODIFY TABLE

SQL> alter table emp modify (jobid char);

Table altered.

SQL> desc emp;

Name Null? Type


----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID CHAR(20)

MGRID VARCHAR2(10)
ADDR VARCHAR2(10)
PHNO VARCHAR2(10)

4. DROP TABLE

SQL> alter table emp drop(phno);

Table altered.

SQL> desc emp;

Name Null? Type

7
----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID CHAR(20)
MGRID VARCHAR2(10)
ADDR VARCHAR2(10)

SQL> alter table emp drop(addr);

Table altered.

SQL> desc emp;

Name Null? Type


----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID CHAR(20)
MGRID VARCHAR2(10)

4.1 DROP THE TABLE


It will delete the table structure provided the table should be empty.

SQL> drop table emp;

Table dropped.

SQL> desc emp;

Object does not exist.

5. TRUNCATE TABLE
If there is no further use of records stored in a table and the structure has to be retained then the
records alone can be deleted.

8
Syntax: TRUNCATE TABLE <TABLE NAME>;

SQL> truncate table emp;

Table truncated.

SQL> desc emp;

Name Null? Type


----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID CHAR(20)
MGRID VARCHAR2(10)

6. RENAME

Can rename the table provided you are the owner of the table.
The generalized syntax is:
RENAME old_table_name TO new_table_name;
Example:
SQL > RENAME emp TO Employee;
Table renamed.
DML COMMANDS

1. INSERT
2. UPDATE
3. DELETE
4. SELECT
1.INSERT COMMAND

1.1 Inserting a single row into a table:


Syntax: insert into <table name> values (value list)

9
SQL> insert into emp values (1,‟A‟,‟AP‟,2, 5000);
1 row created.
1.2 Inserting more than one record using a single insert commands:
Syntax: insert into <table name> values (&col1, &col2, ….)

SQL> insert into emp values(&empno,'&ename','&job',&deptno,&sal);


Enter value for empno: 2
Enter value for ename:B
Enter value for job: AP
Enter value for deptno: 1
Enter value for sal: 10000
old 1: insert into emp values(&empno,'&ename','&job',&deptno,&sal)
new 1: insert into emp values(2,'B','AP',1,10000)
1 row created.

SQL> /
Enter value for empno: 3
Enter value for ename: C
Enter value for job: ASP
Enter value for deptno: 2
Enter value for sal: 15000

old 1: insert into emp values(&empno,'&ename','&job',&deptno,&sal)


new 1: insert into emp values(3,'C','ASP',2,15000)
1 row created.

SQL> /
Enter value for empno: 4
Enter value for ename: D
Enter value for job: ASP
Enter value for deptno: 1
Enter value for sal: 20000
old 1: insert into emp values(&empno,'&ename','&job',&deptno,&sal)
new 1: insert into emp values(4,'D','ASP',1,20000)
1 row created.

SQL> /
Enter value for empno: 5
Enter value for ename: E
Enter value for job: PROF
Enter value for deptno: 2
Enter value for sal: 50000
old 1: insert into emp values(&empno,'&ename','&job',&deptno,&sal)
new 1: insert into emp values(5,'E','PROF',2,50000)
1 row created.
10
2.SELECT COMMANDS

1.Selects all rows from the table


Syntax: Select * from tablename;

SQL> select * from emp;

EMPNO EMPNAME JOB DEPTNO SAL


---------- --------------------- ------------- ------------------- ---------------
1 A AP 2 5000
2 B AP 1 10000
3 C ASP 2 15000
4 D ASP 1 20000
5 E PROF 2 50000

2.The retrieval of specific columns from a table:


It retrieves the specified columns from the table
Syntax: Select column_name1, …..,column_name n from table name;

Query 1: Select employee name, job from the emp table

SQL> select empname,job from emp;

EMPNAME JOB
------------------- ----------------
A AP
B AP
C ASP
D ASP
E PROF

6 rows selected.

3.Elimination of duplicates from the select clause:

It prevents retrieving the duplicated values .Distinct keyword is to be used.


11
Syntax: Select DISTINCT col1, col2 from table name;

Query 2:Display deptno from the table employee avoiding the duplicated values.

SQL> select distinct deptno from emp;

DEPTNO
------------
1
2

4.Select command with where clause:

To select specific rows from a table we include „where‟ clause in the select command.
It can appear only after the „from‟ clause.

Syntax: Select column_name1, …..,column_namen from table name where condition;

Query 3:Display only those employees whose deptno is 30.


.
SQL> select * from emp where deptno=1;

EMPNO EMPNAME JOB DEPTNO SAL


------------ ----------------- ------------ ---------------- -----------
2 B AP 1 10000
4 D ASP 1 20000

5.Select clause with arithmetic expression


SQL> select empno, salary*5 from employee;
Sample Output:
EMPNO SAL
------------ -----------
1 25000
2 50000
3 75000
4 100000
5 250000
3.UPDATE
Syntax: update tablename set field=values where condition;
Query 4: Update the emp table to set the salary of all employees to Rs.30000/- who are
12
working as ASP
SQL> update emp set sal=30000 where job='ASP';

2 rows updated.

SQL> select * from emp;

EMPNO EMPNAME JOB DEPTNO SAL


--------- ---------------- ------------- --------------- -----------
1 A AP 2 5000
2 B AP 1 10000
3 C ASP 2 30000
4 D ASP 1 30000
5 E PROF 2 50000

4. DELETE
Syntax: Delete from table where conditions;
Query 5: Delete only those who are working as Professor
SQL> delete from emp where job='PROF';
1 row deleted.

SQL> select * from emp;

EMPNO EMPNAME JOB DEPTNO SAL


--------- ---------------- ------------- --------------- -----------
1 A AP 2 5000
2 B AP 1 10000
3 C ASP 2 30000
4 D ASP 1 30000

5. CONCATENATION
SQL> select empname || ' is working as ' || job ||' AS "PROFESSION" from emp;

PROFESSION
----------------------------------
A is working as AP.
B is working as AP.
C is working as ASP.

13
D is working as ASP
DCL COMMANDS

1. GRANT COMMAND

Syntax:
Grant < database_priv [database_priv…..] > to <user_name> identified by
<password> [,<password…..];
Grant <object_priv> | All on <object> to <user | public> [With Grant Option ];

2.REVOKE COMMAND

Syntax:
Revoke <database_priv> from <user [, user ] >;
Revoke <object_priv> on <object> from < user | public >;

<database_priv> -- Specifies the system level priveleges to be granted to the users or roles.
This includes create / alter / delete any object of the system.

<object_priv> -- Specifies the actions such as alter / delete / insert / references / execute /
select / update for tables.

<all> -- Indicates all the privileges.

[ With Grant Option ] – Allows the recipient user to give further grants on the objects.

The privileges can be granted to different users by specifying their names or to all users by
using the “Public” option.

TCL COMMANDS

Syntax:
1. SAVEPOINT:

14
SAVEPOINT <SAVE POINT NAME>;
2.ROLLBACK:
ROLL BACK <SAVE POINT NAME>;

3.COMMIT:
Commit;

Q1: Develop a query to grant all privileges of employees table into departments table
Ans:
SQL> Grant all on employees to departments;
Grant succeeded.

Q2: Develop a query to grant some privileges of employees table into departments table
Ans:
SQL> Grant select, update , insert on departments to departments with grant
option;
Grant succeeded.

Q3: Develop a query to revoke all privileges of employees table from departments table
Ans:
SQL> Revoke all on employees from departments;
Revoke succeeded.

Q4: Develop a query to revoke some privileges of employees table from departments table
Ans:
SQL> Revoke select, update , insert on departments from departments;
Revoke succeeded.

Q5: Write a query to implement the save point


Ans:
SQL> SAVEPOINT S1;
Savepoint created.

SQL> select * from emp;


EMPNO ENAME JOB DEPTNO SAL
---------- -------------------- ------------- ---------- ----------
1 Manju AP 1 10000
2 Arav ASP 2 15000
3 Gowtham ASP 1 15000
4 Karthik Prof 2 30000

SQL> INSERT INTO EMP VALUES (5,'Anu','AP',1,10000);


1 row created.

SQL> select * from emp;

15
EMPNO ENAME JOB DEPTNO SAL
---------- -------------------- ------------- ---------- ----------
1 Manju AP 1 10000
2 Arav ASP 2 15000
3 Gowtham ASP 1 15000
4 Karthik Prof 2 30000
5 Anu AP 1 10000

Q6: Write a query to implement the rollback


Ans:
SQL> rollback s1;
SQL> select * from emp;
EMPNO ENAME JOB DEPTNO SAL
---------- -------------------- ------------- ---------- ----------
1 Manju AP 1 10000
2 Arav ASP 2 15000
3 Gowtham ASP 1 15000
4 Karthik Prof 2 30000

Q7: Write a query to implement the commit


Ans:
SQL> COMMIT;
Commit complete.

16
EX.NO:2
Date:
DATABASE QUERYING - SIMPLE QUERIES,NESTED QUERIES,SUBQUERIES AND
JOINS

AIM:
To perform Simple queries, Nested queries, Sub queries and Joins using DML command.

1.NESTED QUERIES:
Nesting of queries one within another is known as a nested query.
2.SUB QUERIES:
The query within another is known as a sub query. A statement containing sub query is
called parent statement. The rows returned by sub query are used by the parent statement.
Types
1. Sub queries that return several values
Sub queries can also return more than one value. Such results should be made use along
with the operators in and any.
2. Multiple queries
Here more than one sub query is used. These multiple sub queries are combined by
means of „and‟ & „or‟ keywords
3. Correlated sub query
A sub query is evaluated once for the entire parent statement whereas a correlated Sub
query is evaluated once per row processed by the parent statement.

BETWEEN:
SQL includes a between comparison operator to specify that a value be less than or equal to
some value and greater than or equal to some other value.
Q1: Find the name of the employees who are receiving salary between 12000 and 25000
SQL > select employee name
from employee

17
where sal between 12000 and 25000;
Sample Output:
no rows selected;

Q2: Find the name of the employees who are receiving salary between 15000 and 30000
SQL > select employee name
from employee
where sal between 15000 and 30000;
Sample Output:
EMPNAME
------------------
B
C
D

AND OR:
The keywords AND and OR are Boolean operators used to specify compound conditions in
the where clause.
Q3: Find the name of the employees who are receiving salary greater than 5000 or all
employees with salary less than 40000 but greater than 10000

SQL > SQL> select empname from emp1718 where sal >5000 and(sal>10000 and
sal<40000);
EMPNAME
--------------------
C
D
LIKE
The LIKE operator is used to filter the result set based on a string pattern. It is always
used in the where clause.
Q4: Find the names of the employees where the first letter starting with A;
SQL > select empname
from employee

18
where empname like ‘a%’
Sample Output:

EMPNAME
-------------------
Anu

NOT LIKE

Q5:Display all the details of the records whose employee name does not starts with ‗A‘.

SQL> select * from emp where ename not like 'A%';

EMPNO ENAME JOB DEPTNO SALARY


-------------- -------------- --------- ------------------- -----------------
1 B AP 1 20000
3 C ASP 2 25000
4 D AP 1 23000

IN AND NOT IN
IN: The in connective tests for set membership.
Q6: Display the Name, Employee Number present in the department number 1.
SQL > select empno,empname
from employee
where deptno in(‘1’);
Sample Output:
EMPNO EMPNAME
------------ -----------------
2 B
4 D

NOT IN: The not in connective tests for the absence of set membership.
Q7: Display the Name, Employee Number who are not present in the department
number 1
SQL > select empno,empname
from employee
where deptno not in(‘1’);

19
Sample Output:
EMPNO EMPNAME
------------ -----------------
1 A
3 C

HAVING

Q8:Display department wise total salary of all employees except for department 3.

SQL> select deptno,sum(sal) from emp1718 group by deptno having deptno<3;

DEPTNO SUM(SAL)
---------- ----------
1 70000
2 10000

ORDERBY

Query 9: List the records in the emp table orderby salary in ascending order.

Ans:
SQL> select * from emp order by sal;

EMPNO EMPNAME JOB DEPTNO SAL


--------- ---------------- ------------- --------------- -----------
1 A AP 2 5000
2 B AP 1 10000
3 C ASP 2 30000
4 D ASP 1 30000

Q10: List the records in the emp table orderby salary in descending order.

Ans:
SQL> select * from emp order by sal desc;

EMPID EMPNAME JOB DEPTNO SAL


----- -------------------- -------------------- ---------- ----------
3 C ASP 1 30000
4 D ASP 1 30000
2 B AP 2 10000
20
1 A AP 1 5000
Q11: Issue a query to find all the employees who work in the same job as Arav.

SQL > select * from emp;

EMPNO ENAME JOB DEPTNO SALARY


-------------- -------------- --------- ------------------- -----------------
1 Manju AP 1 20000
2 Arav ASP 2 30000
3 Gowtham ASP 2 25000
4 Karthik AP 1 23000

SQL> select ename from emp where job= (select job from emp where ename='Arav');

ENAME
--------------
Arav
Gowtham

Q12: Issue a query to display information about employees who earn more than
any employee in dept 1.

SQL> select * from emp where sal>(select max(sal) from emp where empno=1);

EMPNO ENAME JOB DEPTNO SALARY


-------------- -------------- --------- ------------------- -----------------
2 Arav ASP 2 30000
3 Gowtham ASP 2 25000
4 Karthik AP 1 23000

Q13: Display the details of those who draw the salary greater than the average salary.

SQL> select distinct * from emp x where x.sal >= (select avg(sal) from emp);

EMPNO ENAME JOB DEPTNO SALARY


-------------- -------------- --------- ------------------- -----------------
3 Gowtham ASP 2 25000
4 Karthik AP 1 23000

21
NUMERIC FUNCTIONS
Q14:
SQL> select abs(-20) result from dual;

RESULT
---------
20
Q15:
SQL> select power (2,10) result from dual;
RESULT
---------
1024
Q16:
SQL> select round(15.359,2) result from dual;
RESULT
---------
15.36
Q17:
SQL> select sqrt (36) result from dual;

RESULT
---------
6
Q18:
Sql>select mod(5,2) from dual;
RESULT
---------
1

22
STRING FUNCTIONS

Q18:
SQL> select lower('ORACLE') result from dual;
RESULT
------
oracle

Q19:

SQL> select upper('oracle') result from dual;

RESULT
------
ORACLE

Q20:

SQL> select initcap('Oracle') result from dual;

RESULT
------
Oracle

Q21:

SQL> select substr('oracle' ,2 ,5) result from dual;

RESULT
-----
oracle

Q22:

SQL> select lpad('oracle',10,'#') result from dual;

RESULT
----------
####oracle
23
Q23:

SQL> select rpad ('oracle',10,'^') result from dual;

RESULT
----------
oracle^^^^
BUILT-IN DATATYPES IN SQL

 date: Dates, containing a (4 digit) year, month and date

SQL> create table empdates(date1 date);

Table created.

SQL> insert into empdates values('29-Jun-2018');

1 row created.

SQL> select date1 from empdates;

DATE1

---------

29-JUN-18

 time: Time of day, in hours, minutes and seconds.

Example: time „09:00:30‟ time „09:00:30.75‟

 timestamp: date plus time of day

Example: timestamp „2005-7-27 09:00:30.75‟

 interval: period of time

Example: interval „1‟ day

JOIN QUERIES:
The purpose of a join concept is to combine data spread across tables. A join is actually
performed by the “where‟ clause which combines specified rows of tables.

Syntax:
24
Select columns from table1, table2 where logical expression;

Tables used
SQL> select * from emp;

EMPNO ENAME JOB DEPTNO SALARY


-------------- -------------- --------- ------------------- -----------------
1 Manju AP 1 20000
2 Arav ASP 2 30000
3 Gowtham ASP 2 25000
4 Karthik AP 1 23000

SQL > select * from dept;

DEPTNO DNAME LOC


-------------- -------------- ---------
1 Accounts Newyork
2 Research Dallas
3 Sales Chicago
4 Operations Boston

1.SIMPLE JOIN
1. EQUI-JOIN
Q1: Display the employee details, departments that the departments are same in both the
emp and dept.

SQL> select * from emp,dept where emp.deptno=dept.deptno;

EMPNO ENAME JOB DEPTNO SALARY DEPTNO DNAME LOC


----------- -------------- --------- ---------------- ------------ ----------- ---------- --------
1 Manju AP 1 10000 1 Accounts Newyork
2 Arav ASP 2 30000 2 Research Dallas
3 Gowtham ASP 2 25000 2 Research Dallas
4 Karthik AP 1 23000 1 Accounts Newyork

1.2.NON-EQUIJOIN
25
Q2: Display the employee details, departments that the departments are not same in both
the emp and dept.
SQL > select * from emp,dept where emp.deptno!=dept.deptno;

EMPNO ENAME JOB DEPTNO SALARY DEPTNO DNAME LOC


----------- -------------- --------- ---------------- ------------ ----------- ---------- --------
2 Arav ASP 2 30000 1 Accounts Newyork
3 Gowtham ASP 2 25000 1 Accounts Newyork
1 Manju AP 1 10000 2 Research Dallas

EMPNO ENAME JOB DEPTNO SALARY DEPTNO DNAME LOC


----------- -------------- --------- ---------------- ------------ ----------- ---------- --------
4 Karthik AP 1 23000 2 Research Dallas
1 Manju AP 1 30000 3 Sales Chicago
2 Arav ASP 2 10000 3 Sales Chicago

EMPNO ENAME JOB DEPTNO SALARY DEPTNO DNAME LOC


----------- -------------- --------- ---------------- ------------ ----------- ---------- --------
3 Gowtham AP 2 25000 3 Sales Chicago
4 Karthik AP 1 23000 3 Sales Chicago
1 Manju AP 1 30000 4 Operations Boston

EMPNO ENAME JOB DEPTNO SALARY DEPTNO DNAME LOC


----------- -------------- --------- ---------------- ------------ ----------- ---------- --------
2 Arav ASP 2 30000 4 Operations Boston
3 Gowtham ASP 2 25000 4 Operations Boston
4 Karthik AP 1 23000 4 Operations Boston

3.INNER JOIN
 Inner join returns the matching rows from the tables that are being joined.
Syntax:
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_field = table2.common_field;
 Consider the following two relations :
i) Employee(Emp_name, City)
26
EMP_NAME CITY
Hari Pune
OM Mumbai
Smith Nashik
Jay Solapur

ii) Employee_Salary (Emp_name, Department ,Salary )

EMPLOYEE

i)

EMPLOYEE_SALARY

EMP_NAME DEPARTMENT SALARY


Hari Computer 10000

OM IT 7000
Hill Computer 8000
Jay IT 5000

Example:

SQL > select Employee.emp_name ,Employee_salary.Salary


from Employee inner join Employee_salary on
Employee.Emp_name = Employee_salary.Emp_name;
Sample Output:

EMP_NAME SALARY

27
Hari 10000
OM 7000
Jay 5000

4.OUTER JOIN
An outer join returns all the rows returned by simple join as well as those rows from one
table that do not match any row from the table. The symbol (+) represents outer join.
4.1 LEFT OUTER JOIN

The SQL LEFT JOIN returns all rows from the left table, even if there are no matches in
the right table.
Syntax:
SELECT table1.column1, table2.column2...
FROM table1
LEFT OUTER JOIN table2
ON table1.common_field = table2.common_field;

SQL > select Employee.emp_name ,Employee_salary.Salary


from Employee left outer join Employee_salary on
Employee.Emp_name = Employee_salary.Emp_name;
Sample Output:

EMP_NAME SALARY
Hari 10000
OM 7000
Smith
Jay 5000

4.2 RIGHT OUTER JOIN -

The SQL RIGHT JOIN returns all rows from the right table, even if there are no matches
in the left table.
Syntax:

28
SELECT table1.column1, table2.column2...
FROM table1
RIGHT OUTER JOIN table2
ON table1.common_field = table2.common_field;

SQL > select Employee.emp_name,Employee.city,Employee_salary.Salary


from Employee right outer join Employee_salary on
Employee.Emp_name = Employee_salary.Emp_name;
Sample Output:

EMP_NAME CITY SALARY


Hari Pune 10000
OM Mumbai 7000
Jay Solapur 5000
Hill 8000

4.3 FULL OUTER JOIN

The SQL FULL JOIN combines the results of both left and right outer joins.
Syntax:
SELECT table1.column1, table2.column2...
FROM table1
FULL OUTER JOIN table2
ON table1.common_filed = table2.common_field;

SQL > select Employee.emp_name,Employee.city,Employee_salary.Salary


from Employee full outer join Employee_salary on
Employee.Emp_name = Employee_salary.Emp_name;
Sample Output:

EMP_NAME CITY SALARY


Hari Pune 10000

29
OM Mumbai 7000
Smith Nashik
Jay Solapur 5000
Hill 8000

CONSTRAINTS
1. NOT NULL CONSTRAINT
Ensures that a column cannot have NULL value.
2. DEFAULT CONSTRAINT
Provides a default value for a column when none is specified.
3. UNIQUE CONSTRAINT
Ensures that all values in a column are different.
4. PRIMARY KEY
Uniquely identified each rows/records in a database table.
5. FOREIGN KEY
Uniquely identified a rows/records in any another database table.
6. CHECK CONSTRAINT
The CHECK constraint ensures that all values in a column satisfy certain conditions.

Queries
Q1. Create the employee table with NOT NULL and PRIMARY KEY constraint.
Ans:

SQL > CREATE TABLE EMPLOYEE (ID INT NOT NULL, NAME VARCHAR (20) NOT
NULL, AGE INT NOT NULL, ADDRESS CHAR (25), SALARY DECIMAL (18, 2),
PRIMARY KEY (ID));
Table created.
SQL > desc employee;

Name Null? Type


-------------------------- --------------- ----------------------------
ID NOT NULL INT
30
NAME NOT NULL VARCHAR2(20)
AGE NOT NULL INT
ADDRESS CHAR(25)
SALARY DECIMAL(18,2)

Q2. Alter the NOT NULL constraint for the employee table
Ans:
SQL > ALTER TABLE CUSTOMERS MODIFY SALARY DECIMAL (18, 2) NOT NULL;
Table altered.
SQL > desc employee;

Name Null? Type


-------------------------- --------------- ----------------------------
ID NOT NULL INT
NAME NOT NULL VARCHAR2(20)
AGE NOT NULL INT
ADDRESS CHAR(25)
SALARY NOT NULL DECIMAL(18,2)

Q3.Create the employee table using Default constraint and insert values into the table.
Ans:
SQL > CREATE TABLE EMPLOYEE (ID INT NOT NULL, NAME VARCHAR (20) NOT
NULL, AGE INT NOT NULL, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2)
DEFAULT 5000.00, PRIMARY KEY (ID));
Table created.

SQL > INSERT into employee values ('&ID ',‟&NAME‟, &AGE , '&ADDRESS', &SALARY);

Enter value for ID: 01

Enter value for NAME: Arav

Enter value for AGE: 24

Enter value for ADDRESS: New Street

Enter value for SALARY :

Old 1: insert into employee values ('&id ',‟&name‟, &age, '&address', &salary);
31
New 1: insert into employee values (01,‟Arav‟, 24,‟New street‟, 5000);

Q4.Display the employee table


Ans:
SQL > select * from employee;

ID NAME AGE ADDRESS SALARY


----------- --------------- ----------- ------------------ ---------------
1 Arav 24 New street 5000

Q5.Create the employee table using Unique constraint.


Ans:
SQL > CREATE TABLE EMPLOYEE (ID INT NOT NULL, NAME VARCHAR (20)
UNIQUE, AGE INT NOT NULL, ADDRESS CHAR (25), SALARY DECIMAL (18, 2),
PRIMARY KEY (ID));
Table created.

SQL > INSERT into employee values ('&ID ',‟&NAME‟, &AGE, '&ADDRESS', &SALARY);

Enter value for ID: 01

Enter value for NAME: Arav

Enter value for AGE: 24

Enter value for ADDRESS: New Street

Enter value for SALARY: 6000

Old 1: insert into employee values ('&id ',‟&name‟, &age, '&address', &salary);

New 1: insert into employee values (01,‟Arav‟, 24,‟New street‟, 6000);

SQL > /
Enter value for ID: 02

Enter value for NAME: Arav

Enter value for AGE: 34


32
Enter value for ADDRESS: Fifth colony

Enter value for SALARY: 4000

Old 1: insert into employee values ('&id ',‟&name‟, &age, '&address', &salary);

New 1: insert into employee values (02,‟Arav‟, 34,‟Fifth colony‟, 4000);

insert into employee values (02,‟Arav‟, 34,‟Fifth colony‟, 4000);

ERROR at line 1:

ORA-02290: unique constraint (SCOTT.B) violated

Q6.Create the employee database in which the age of the employee should be above 25
Ans:
SQL > CREATE TABLE EMPLOYEE (ID INT NOT NULL, NAME VARCHAR (20)
UNIQUE, AGE INT NOT NULL CHECK (AGE>25), ADDRESS CHAR (25), SALARY
DECIMAL (18, 2), PRIMARY KEY (ID));
Table created.

SQL > INSERT into employee values ('&ID ',‟&NAME‟, &AGE, '&ADDRESS', &SALARY);

Enter value for ID: 03

Enter value for NAME: Dinesh

Enter value for AGE: 22

Enter value for ADDRESS: kalyan nagar

Enter value for SALARY: 7000

Old 1: insert into employee values ('&id ',‟&name‟, &age, '&address', &salary);

New 1: insert into employee values (03,‟Dinesh‟, 22,‟kalyan nagar‟, 7000);

insert into employee values (03,‟Dinesh‟, 22,‟kalyan nagar‟, 7000);

33
ERROR at line 1:

ORA-02290: check constraint (SCOTT.B) violated

Q7. Create a foreign Key for the department table.


Ans:
SQL > CREATE TABLE DEPARTMENT (D_ID INT NOT NULL, NAME VARCHAR (20),
EMPLOYEE_ID INT references EMPLOYMENT(ID) , PRIMARY KEY (D_ID));
Table created.

AGGREGATE FUNCTIONS:
 Functions that take a collection of values as input and return a single value.
 SQL offers five built-in aggregate functions
1. Average : avg
2. Minimum :min
3. Maximum : max
4. Total : sum
5. Count : count
1) Avg
Syntax: avg([Distinct | All | n)
Purpose : Returns average value of n,ignoring null values.
Example :
SQL > select avg(salary) as Average Salary
from employee;
Sample Output:

AVERAGE SALARY
---------------------------
16000
2) Min
Syntax: min ([Distinct | All | expression)
34
Purpose : Returns minimum value of expression
Q2: Determine the minimum salary and rename the column as min_salary.
SQL > select min(salary) as Minimum Salary
from employee;
Sample Output:

MINIMUM SALARY
---------------------------
10000
3) Max
Q3: Determine the maximum salary and rename the column as max_salary.
Syntax: max ([Distinct | All | expression)
Purpose : Returns maximum value of expression
Example :
SQL > select max (salary) as Maximum Salary
from employee;
Sample Output:
MAXIMUM SALARY
---------------------------
30000
4) Sum
Syntax: sum ([Distinct | All | n)
Purpose : Returns sum of values of n
Example :
SQL > select sum (salary) as Total
from employee;
Sample Output:
TOTAL
---------------------------
80000

5) Count - In order to count the number of rows, count function is used.

35
count(*) – It counts all, inclusive of duplicates and nulls.
count(col_name)– It avoids null value.
count(distinct col_name) – It avoids the repeated and null values.

Syntax: count ([Distinct | All | expression )


Q4:Find how many department are available in employee table.
SQL > select count (dname) as No.of.Dept
from employee;
Sample Output:

NO.OF DEPT
--------------------------
4

SQL > select count(*) from emp;

COUNT(*)
-------------
4

SET OPERATIONS
CREATE PRODUCT TABLE
SQL> create table product(prodname varchar2(30), prodno varchar2(10));
Table created.
SQL> select * from product;
PRODNAME PRODNO
------------------------------ ----------
table 10001
chair 10010
desk 10110
cot 11110
sofa 10010
36
tvstand 11010

CREATE SALE TABLE


SQL> create table sale(prodname varchar2(30),orderno number(10),prodno varchar2(10));
Table created.

SQL> select * from sale;


PRODNAME ORDERNO PRODNO
------------------------------ --------- ----------
table 801 10001
chair 805 10010
desk 809 10110
cot 813 11110
sofa 817 10010
UNION
SQL> select prodname from product where prodno=10010 union select prodname from sale
where prodno=10010;

PRODNAME
------------------------------
chair
sofa

INTERSECT
SQL> select prodname from product where prodno=11110 intersect
select prodname from sale where prodno=11110;
PRODNAME
------------------------------
cot
NESTED QUERIES

37
SQL> select * from sstud1;
SNAME PLACE
-------------------- --------------------
prajan chennai
anand chennai
kumar chennai
ravi Chennai

SQL> select * from sstud2;


SNAME DEPT MARKS
-------------------- ---------- ---------
prajan cse 700
anand it 650
vasu cse 680
ravi it 600

SQL> select sname from sstud1 where sstud1.sname in ( select sstud2.sname from sstud2 );
SNAME
--------------------
anand
prajan
ravi

SQL> select sname from sstud1 where sstud1.sname not in ( select sstud2.sname from sstud2 );
SNAME
--------------------
Kumar

38
SQL> select sname from sstud2 where marks > some(select marks from sstud2 where
dept='cse');
SNAME
--------------------
prajan

SQL> select sname from sstud2 where marks >= some (select marks from sstud2 where
dept='cse' );
SNAME
--------------------
prajan
vasu

SQL> select sname from sstud2 where marks > any ( select marks from sstud2 where dept='cse'
);

SNAME
--------------------
Prajan

SQL> select sname from sstud2 where marks >= any ( select marks from sstud2 where dept='cse'
);

SNAME
--------------------
prajan
vasu

SQL> select sname from sstud2 where marks > all ( select marks from sstud2 where dept='cse' );
no rows selected

39
SQL> select sname from sstud2 where marks < all ( select marks from sstud2 where dept='cse' );

SNAME
--------------------
anand
ravi

SQL> select sname from sstud1 where exists ( select sstud2.sname from sstud2 where
sstud1.sname=sstud2.sname );
SNAME
--------------------
prajan
anand
ravi

SQL> select sname from sstud1 where not exists ( select sstud2.sname from sstud2 where
sstud1.sname=sstud2.sname );
SNAME
--------------------
kumar

40
EX.NO:3

Date:

VIEWS, SYNONYMS AND SEQUENCES

AIM:

To execute SQL commands for creating Views, Synonyms and Sequences

1. VIEWS:

A view is a “virtual table” or a “stored query” which takes the Sample Output of a query
and treats it as a table. The table upon which a view is created is called as base table.

Creating and dropping view:


Syntax:
Create [or replace] view <view name> [column alias names] as <query> [with <options>
conditions];
Drop view <view name>;
Example:
Create or replace view empview as select * from emp;
Drop view empview;

2. SYNONYMS:
A synonym is an alias, that is, a form of shorthand used to simplify the task of
referencing a database object.
Creating Synonym:
Syntax:
CREATE [PUBLIC] SYNONYM synonym_name FOR object_name;

Drop Synonym:
Syntax:
DROP SYNONYM synonym_name;
41
DROP PUBLIC SYNONYM synonym_name;

Rename Synonym:
Syntax:
RENAME old_synonym_name TO new_synonym_name;

3. SEQUENCES:
Sequences are used to generate unique, sequential integer values that are used as primary
key values in database tables. The sequence of numbers can be generated in either
ascending or descending order.
Creating Sequences:
Syntax:
CREATE SEQUENCE <sequence name>
[INCREMENT BY <number>]
[START WITH <start value number>]
[MAXVALUE <MAXIMUM VLAUE NUMBER>]
[NOMAXVALUE]
[MINVALUE <minimum value number>]
[CYCLE]
[NOCYCLE]
[CACHE <number of sequence value to cache>]
[NOCACHE]
[ORDER]
[NOORDER];
Drop Sequences:
Syntax:
DROP SEQUENCE <sequence name>;

4. INDEXES

42
An index can be created in a table to find data more quickly and efficiently. The users
cannot see the indexes; they are just used to speed up searches/queries.
Create Index:
Syntax:
CREATE INDEX index_name
ON table_name(column_name)

Create Unique Index:


Syntax:
CREATE UNIQUE INDEX index_name
ON table_name(column_name)
Drop Index:
Syntax:
DROP INDEX index_name;
Queries:
Tables used:
SQL> select * from emp;
EMPNO ENAME JOB DEPTNO SALARY
-------------- -------------- --------- ------------------- -----------------
1 Manju AP 1 20000
2 Arav ASP 2 30000
3 Gowtham ASP 2 25000
4 Karthik AP 1 23000

Q1: The organization wants to display only the details of the employees those who are ASP.
(Horizontal portioning)

SQL> create view empview as select * from emp where job='ASP';


View created.
SQL> select * from empview;
EMPNO ENAME JOB DEPTNO SAL
---------- ------------ -------- ---------- ----------
2 Arav ASP 2 30000
3 Gowt ASP 2 25000
43
Q2: The organization wants to display only the details like empno, empname, deptno,
deptname of the employees. (Vertical portioning)

SQL> create view empview1 as select ename,sal from emp;


View created.
Q3: Display all the views generated.

SQL> select * from tab;


TNAME TABTYPE CLUSTERID
---------------- -------------- -------- --------
DEPT TABLE
EMP TABLE
EMPVIEW VIEW
EMPVIEW1 VIEW

Q4: The Organization wants to update the salary of an employee


SQL>UPDATE empview SET sal=28000
WHERE empno=3;
1 row updated.

SQL> select * from empview;

EMPNO ENAME JOB DEPTNO SAL


---------- ------------ -------- ---------- ----------
2 Arav ASP 2 30000
3
Gowtham ASP 2 28000

Q5: Delete the particular employee.


SQL> DELETE empview
WHERE ename=‟Gowtham‟;
1 row deleted.

SQL> select * from empview;

EMPNO ENAME JOB DEPTNO SAL


---------- ------------ -------- ---------- ----------
2 Arav ASP 2 30000

Q6: Drop a view.


SQL> drop view empview1;
View dropped.
44
Q7.Create the sales order table.
SQL>CREATE TABLE sales_order (order_number NUMBER(10),PRIMARY
KEY(order_number) , order_amount NUMBER(9,2));

Q7.Create sequence for the sales order table.


Ans:
SQL> CREATE SEQUENCE order_number_sequence
INCREMENT BY 1
START WITH 1
MAXVALUE 100000000
MINVALUE 1
CYCLE
CACHE 10;
Sequence created.
Q8.Write the Query for inserting values into the sales order table.
Ans:
SQL> INSERT INTO sales_order VALUES(order_number_sequence.nextval, 155.59 );
SQL> INSERT INTO sales_order VALUES(order_number_sequence.nextval,450.00 );
SQL> INSERT INTO sales_order VALUES(order_number_sequence.nextval,16.95);
Q9.Display the sales_order table.
Ans:
SQL > SELECT * FROM sales_order;
ORDER_NUMBER ORDER_AMOUNT
-------------------------- --------------------------
1 155.59
2 450
3 16.95

45
Q10. Alter the maximum value of the order number.
Ans:
SQL> ALTER SEQUENCE order_number_sequence MAXVALUE 200000000;
Sequence altered.
Q11. Display the names and properties of the Sequences.
Ans:
SQL> SELECT * from USER_SEQUENCES;
SEQUENCE_NAME MIN_VALUE MAX_VALUE INCRE C O CACHE_SIZE LAST_N
-------------------------- ----------------- ------------------ --------- -- --- ------------------- -------------
ORDER_NUMBER_ 1 200000000 1 Y N 10 3
SEQUENCE

Q12.Drop the sequence


Ans:
DROP SEQUENCE order_number_sequence;
Sequence dropped.
Q13.Create the synonym for emp table.
Ans:
SQL > CREATE synonym EMPLOYEE_DETAILS for EMP;
Synonym created.
SQL> select * from EMPLOYEE_DETAILS;
EMPNO ENAME JOB DEPTNO SALARY
-------------- -------------- --------- ------------------- -----------------
1 Manju AP 1 20000
2 Arav ASP 2 30000
3 Gowtham ASP 2 25000
4 Karthik AP 1 23000

SQL> select * from EMP;


EMPNO ENAME JOB DEPTNO SALARY
-------------- -------------- --------- ------------------- -----------------
1 Manju AP 1 20000
2 Arav ASP 2 30000
3 Gowtham ASP 2 25000
4 Karthik AP 1 23000
46
Q14. Display the synonym.
Ans:
SQL > show synonyms;
Q15. Drop the synonym.
Ans:
SQL > DROP synonym EMPLOYEE_DETAILS;
synonym dropped.
Q16. Create index for the employee table.
Ans:
SQL > CREATE index PIndex on emp (ename);
index created;
Q17. Drop the index.
Ans:
SQL > DROP index PIndex;

47
EX.NO.4
Date:

IMPLICIT AND EXPLICIT CURSORS


AIM:
To execute Database Programming using Implicit and Explicit Cursors.

CURSORS
 A cursor is a pointer to this context area. PL/SQL controls the context area through a
cursor.
 A cursor holds the rows (one or more) returned by a SQL statement. The set of rows the
cursor holds is referred to as the active set.
 There are two types of cursors −
1. Implicit cursors
2. Explicit cursors
1. IMPLICIT CURSORS
 Implicit cursors are automatically created by Oracle whenever an SQL statement is
executed, when there is no explicit cursor for the statement. Programmers cannot control
the implicit cursors and the information in it.
 Whenever a DML statement (INSERT, UPDATE and DELETE) is issued, an implicit
cursor is associated with this statement.
 For INSERT operations, the cursor holds the data that needs to be inserted. For
UPDATE and DELETE operations, the cursor identifies the rows that would be
affected.

S.NO ATTRIBUTE & DESCRIPTION


%FOUND
Returns TRUE if an INSERT, UPDATE, or DELETE statement affected
1
one or more rows or a SELECT INTO statement returned one or more
rows. Otherwise, it returns FALSE.
%NOTFOUND
2
The logical opposite of %FOUND. It returns TRUE if an INSERT,

48
UPDATE, or DELETE statement affected no rows, or a SELECT INTO
statement returned no rows. Otherwise, it returns FALSE.
%ISOPEN
3 Always returns FALSE for implicit cursors, because Oracle closes the SQL
cursor automatically after executing its associated SQL statement.
%ROWCOUNT
4 Returns the number of rows affected by an INSERT, UPDATE, or
DELETE statement, or returned by a SELECT INTO statement.

Q1: Write SQL query to increase the salary of each customer by 500 using cursors.

Select * from customers;

ID NAME AGE ADDRESS SALARY


------ ------------- ------- -------------- --------------
1 Ramesh 32 Ahmedabad 2000.00
2 Khilan 25 Delhi 1500.00
3 Kaushik 23 Kota 2000.00
4 Chaitali 25 Mumbai 6500.00
5 Hardik 27 Bhopal 8500.00
6 Komal 22 MP 4500.00

DECLARE

total_rows number(2);

BEGIN

UPDATE customers

SET salary = salary + 500;

IF sql%notfound THEN

dbms_Sample Output.put_line('no customers selected');

ELSIF sql%found THEN

total_rows := sql%rowcount;
49
dbms_Sample Output.put_line( total_rows || ' customers selected ');

END IF;

END;

Sample Output:

6 customers selected

PL/SQL procedure successfully completed.

Select * from customers;

ID NAME AGE ADDRESS SALARY


------ ------------- ------- -------------- --------------
1 Ramesh 32 Ahmedabad 2500.00
2 Khilan 25 Delhi 2000.00
3 Kaushik 23 Kota 2500.00
4 Chaitali 25 Mumbai 7000.00
5 Hardik 27 Bhopal 9000.00
6 Komal 22 MP 5000.00

2.EXPLICIT CURSORS
 Explicit cursors are programmer-defined cursors for gaining more control over
the context area.
 An explicit cursor should be defined in the declaration section of the PL/SQL Block. It is
created on a SELECT Statement which returns more than one row.
 The syntax for creating an explicit cursor is −
CURSOR cursor_name IS select_statement;

 Working with an explicit cursor includes the following steps −


1. Declaring the cursor for initializing the memory
2. Opening the cursor for allocating the memory

50
3. Fetching the cursor for retrieving the data
4. Closing the cursor to release the allocated memory
2.1 Declaring the Cursor
Declaring the cursor defines the cursor with a name and the associated SELECT statement.
Example −

CURSOR c_customers IS

SELECT id, name, address FROM customers;


2.2 Opening the Cursor
Opening the cursor allocates the memory for the cursor and makes it ready for fetching the rows
returned by the SQL statement into it.
Example

OPEN c_customers;
2.3 Fetching the Cursor
Fetching the cursor involves accessing one row at a time.
Example

FETCH c_customers INTO c_id, c_name, c_addr;


2.4 Closing the Cursor
Closing the cursor means releasing the allocated memory.
Example

CLOSE c_customers;

Q2: Write query for displaying customer details using explicit cursors

DECLARE

c_id customers.id%type;

c_name customerS.No.ame%type;

c_addr customers.address%type;

CURSOR c_customers is

SELECT id, name, address FROM customers;

51
BEGIN

OPEN c_customers;

LOOP

FETCH c_customers into c_id, c_name, c_addr;

EXIT WHEN c_customers%notfound;

dbms_Sample Output.put_line(c_id || ' ' || c_name || ' ' || c_addr);

END LOOP;

CLOSE c_customers;

END;

Ouput:
1 Ramesh Ahmedabad
2 Khilan Delhi
3 kaushik Kota
4 Chaitali Mumbai
5 Hardik Bhopal
6 Komal MP

PL/SQL procedure successfully completed.

Q3:Cursor Program For Electricity Bill Calculation:

SQL> create table bill (name varchar2(10), address varchar2(20), city varchar2(20), unit
number(10));

Table created.

SQL> insert into bill values('&name','&addess','&city','&unit');


Enter value for name: yuva
Enter value for addess: srivi
52
Enter value for city: srivilliputur
Enter value for unit: 100
old 1: insert into bill values('&name','&addess','&city','&unit')
new 1: insert into bill values('yuva','srivi','srivilliputur','100')
1 row created.

SQL> /
Enter value for name: nithya
Enter value for addess: Lakshmi nagar
Enter value for city: sivakasi
Enter value for unit: 200
old 1: insert into bill values('&name','&addess','&city','&unit')
new 1: insert into bill values('nithya','Lakshmi nagar','sivakasi','200')
1 row created.

SQL> /
Enter value for name: maya
Enter value for addess: housing board
Enter value for city: sivakasi
Enter value for unit: 300
old 1: insert into bill values('&name','&addess','&city','&unit')
new 1: insert into bill values('maya','housing board','sivakasi','300')
1 row created.

SQL> /
Enter value for name: jeeva
Enter value for addess: RRR nagar
Enter value for city: sivaganagai
Enter value for unit: 400
old 1: insert into bill values('&name','&addess','&city','&unit')
new 1: insert into bill values('jeeva','RRR nagar','sivaganagai','400')
1 row created.

SQL> select * from bill;

NAME ADDRESS CITY UNIT

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

Yuva srivi srivilliputur 100

Nithya Lakshmi nagar sivakasi 200

maya housing board sivakasi 300

jeeva RRR nagar sivaganagai 400


53
SQL> declare

2 cursor c is select * from bill;

3 b bill %ROWTYPE;

4 begin

5 open c;

6 dbms_Sample Output.put_line('Name Address city Unit Amount');

7 loop

8 fetch c into b;

9 if(c % notfound) then

10 exit;

11 else

12 if(b.unit<=100) then

13 dbms_Sample Output.put_line(b.name||' '||b.address||' '||b.city||' '||b.unit||' '||b.unit*1);

14 elsif(b.unit>100 and b.unit<=200) then

15 dbms_Sample Output.put_line(b.name||' '||b.address||' '||b.city||' '||b.unit||' '||b.unit*2);

16 elsif(b.unit>200 and b.unit<=300) then

17 dbms_Sample Output.put_line(b.name||' '||b.address||' '||b.city||' '||b.unit||' '||b.unit*3);

18 elsif(b.unit>300 and b.unit<=400) then

19 dbms_Sample Output.put_line(b.name||' '||b.address||' '||b.city||' '||b.unit||' '||b.unit*4);

20 else

21 dbms_Sample Output.put_line(b.name||' '||b.address||' '||b.city||' '||b.unit||' '||b.unit*5);

22 end if;

54
23 end if;

24 end loop;

25 close c;

26 end;

27 /

Sample Output:

NAME ADDRESS CITY UNIT AMOUNT

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

Yuva srivi srivilliputur 100 100

Nithya Lakshmi nagar sivakasi 200 400

maya housing board sivakasi 300 900

jeeva RRR nagar sivaganagai 400 1600

PL/SQL procedure successfully completed.

55
EX.NO.5
Date:

PROCEDURES AND FUNCTIONS


AIM:
To develop Procedures and Function for various operations.

PL/SQL
Syntax:
A procedure is a block that can take parameters (sometimes referred to as
arguments) and be invoked.
Procedures promote reusability and maintainability. Once validated, they can be used
in number of applications. If the definition changes, only the procedure are affected, this
greatly simplifies maintenance.
Modularized program development:
· Group logically related statements within blocks.
· Nest sub-blocks inside larger blocks to build powerful programs.
· Break down a complex problem into a set of manageable well defined logical
modules and implement the modules with blocks.

KEYWORDS AND THEIR PURPOSES

REPLACE: It recreates the procedure if it already exists.


PROCEDURE: It is the name of the procedure to be created.
ARGUMENT: It is the name of the argument to the procedure. Parenthesis can be omitted
if no arguments are present.
IN: Specifies that a value for the argument must be specified when calling the procedure ie.,
used to pass values to a sub-program. This is the default parameter.
OUT: Specifies that the procedure passes a value for this argument back to it‟s calling
environment after execution ie. used to return values to a caller of the sub-program.
INOUT: Specifies that a value for the argument must be specified when calling the
procedure and that procedure passes a value for this argument back to it‟s calling

56
environment after execution.
RETURN: It is the data type of the function‟s return value because every function must
return a value, this clause is required.
PROCEDURES

Syntax:
create or replace procedure <procedure name> (argument {in,out,inout}
datatype ) {is,as} variable declaration;
constant declaration;
begin
PL/SQL subprogram body;
exception
exception
PL/SQL block;
end;

EXECUTION
SETTING SERVERSAMPLE OUTPUT ON:
SQL> SET SERVERSAMPLE OUTPUT ON

Q1: Procedure Using Positional Parameters


SQL> SET SERVERSAMPLE OUTPUT ON
SQL> CREATE OR REPLACE PROCEDURE PROC1 AS
2 BEGIN
3 DBMS_SAMPLE OUTPUT.PUT_LINE('Hello from procedure...');
4 END;
5/
Sample Output:
Procedure created.
SQL> EXECUTE PROC1
Hello from procedure...
PL/SQL procedure successfully completed.

57
Q2) Procedure Using Notational Parameters:

SQL> CREATE OR REPLACE PROCEDURE PROC2


2 (N1 IN NUMBER,N2 IN NUMBER,TOT OUT NUMBER) IS
3 BEGIN
4 TOT := N1 + N2;
5 END;
6/

Sample Output:
Procedure created.
SQL> VARIABLE T NUMBER
SQL> EXEC PROC2(33,66,:T)
PL/SQL procedure successfully completed.
SQL> PRINT T
T
----------
99

Q3: Write Procedure for calculating GCD of two numbers.


SQL> create or replace procedure pro
is
a number(3);
b number(3);
c number(3);
d number(3);
begin
a:=&a;
b:=&b;
if(a>b) then

58
c:=mod(a,b);
if(c=0) then
dbms_Sample Output.put_line('GCD is');
dbms_Sample Output.put_line(b);
else
dbms_Sample Output.put_line('GCD is');
dbms_Sample Output.put_line(c);
end if;
else
d:=mod(b,a);
if(d=0) then
dbms_Sample Output.put_line('GCD is');
dbms_Sample Output.put_line(a);
else
dbms_Sample Output.put_line('GCD is');
dbms_Sample Output.put_line(d);
end if;
end if;
end;
/
SAMPLE OUTPUT:
Enter value for a: 8
old 8: a:=&a;
new 8: a:=8;
Enter value for b: 16
old 9: b:=&b;
new 9: b:=16;
Procedure created.
SQL> set serverSample Output on;
SQL> execute pro;

59
GCD is
8
PL/SQL procedure successfully completed.

TABLES USED:
SQL> select * from items;
ITEMID ACTUALPRICE ORDID PRDID
--------- ----------- -------- ---------
101 2000 500 201
102 3000 1600 202
103 4000 600 202

Q4. Selected Record’s Price Is Incremented By 500, Executing the Procedure Created And
Displaying The Updated Table
PROGRAM:
SQL> create procedure itsum(identity number, total number) is price number;
2 null_price exception;
3 begin
4 select actualprice into price from items where itemid=identity;
5 if price is null then
6 raise null_price;
7 else
8 update items set actualprice=actualprice+total where itemid=identity;
9 end if;
10 exception
11 when null_price then
12 dbms_Sample Output.put_line('price is null');
13 end;
14 /
Procedure created.

60
SQL> exec itsum(101, 500);
PL/SQL procedure successfully completed.

SQL> select * from items;


ITEMID ACTUALPRICE ORDID PRDID
--------- ----------- -------- ---------
101 2500 500 201
102 3000 1600 202
103 4000 600 202

Q5. Procedure for ‘IN‘ parameter – creation, execution


SQL> set serverSample Output on;
SQL> create procedure yyy (a IN number) is price number;
2 begin
3 select actualprice into price from items where itemid=a;
4 dbms_Sample Output.put_line('Actual price is ' || price);
5 if price is null then
6 dbms_Sample Output.put_line('price is null');
7 end if;
8 end;
9 /
Procedure created.
SQL> exec yyy(103);
Actual price is 4000
PL/SQL procedure successfully completed.

Q6. Procedure for ‘OUT‘ parameter – creation, execution

SQL> set serverSample Output on;


SQL> create procedure zzz (a in number, b out number) is identity number;
61
2 begin
3 select ordid into identity from items where itemid=a;
4 if identity<1000 then
5 b:=100;
6 end if;
7 end;
8 /
Procedure created.

SQL> declare
2 a number;
3 b number;
4 begin
5 zzz(101,b);
6 dbms_Sample Output.put_line('The value of b is '|| b);
7 end;
8 /
The value of b is 100
PL/SQL procedure successfully completed.

Q7. Procedure for ‘INOUT‘ parameter – creation, execution


SQL> create procedure itit ( a in out number) is
2 begin
3 a:=a+1;
4 end;
5 /
Procedure created.

SQL> declare
2 a number:=7;

62
3 begin
4 itit(a);
5 dbms_Sample Output.put_line(„The updated value is „||a);
6 end;
7 /
The updated value is 8
PL/SQL procedure successfully completed.
Q8. Write a procedure to calculate total for the all the students and pass regno, mark1, &
mark2 as arguments.
PROCEDURE:
1 Develop a query to create a table named itstudent2 and insert values into them
2 Develop a procedure p1 with regno, mark1, & mark2 as arguments.
3 Calculate the total and update the total value into the itstudent2 table

SQL> create table itstudent2(regno number(3),name varchar(9),mark1 number(3),mark2


number(3));
Table created.

SQL> insert into itstudent2values(&a,'&b',&c,&d);

Enter value for a: 110


Enter value for b: arun
Enter value for c: 99
Enter value for d: 100
Old 2: values(&a,'&b',&c,&d)
New 2: values(110,'arun',99,100)
1 row created.

SQL> /
Enter value for a: 112
Enter value for b: siva

63
Enter value for c: 99
Enter value for d: 90
Old 2: values(&a,'&b',&c,&d)
New 2: values(112,'siva',99,90)
1 row created.

SQL> select * from itstudent2;


REGNO NAME MARK1 MARK2
----------- ----------- ------------ ------------
110 arun 99 100
112 siva 99 90
SQL> alter table itstudent2 add(total number(5));
Table altered.
SQL> select * from itstudent2;
REGNO NAME MARK1 MARK2 TOTAL
---------- ---------- ------------ ----------- ----------
110 arun 99 100
112 siva 99 90

SQL> create or replace procedure p1(sno number,mark1 number,mark2 number) is


2 tot number(5);
3 begin
4 tot:=mark1+mark2;
5 update itstudent2 set total=tot where regno=sno;
6 end;
7 /
Procedure created.

SQL> declare
2 cursor c1 is select * from itstudent2;
3 rec itstudent2 % rowtype;
4 begin
64
5 open c1;
6 loop
7 fetch c1 into rec;
8 exit when c1%notfound;
9 p1(rec.regno,rec.mark1,rec.mark2);
10 end loop;
11 close c1;
12 end;
13 /

PL/SQL procedure successfully completed.

SAMPLE OUTPUT:

SQL> select * from itstudent2;

REGNO NAME MARK1 MARK2 TOTAL


------------ -------------- ------------- ------------- ----------------
110 arun 99 100 199
112 siva 99 80 179

Q9: Write a PL/SQL procedure called MULTI_TABLE that takes two numbers as parameter and
displays the multiplication of the first parameter till the second parameter.

PROGRAM :
//p2.sql
create or replace procedure multi_table (a number, b number)
as mul number;
begin
for i in 1. .b loop
mul : = a * i;
dbms_Sample Output.put_line (a || „*‟ || i || „=‟ ||
mul);
end loop;
65
end;
//pq2.sql
declare
a number; b number;
begin
a:=&a;
b:=&b;
multi_table(a,b);
end;

SAMPLE OUTPUT:

SQL> @p2.sql;
Procedure created.
SQL> @pq2.sql;
Enter value for a: 4
old 5: a:=&a; new 5: a:=4;
Enter value for b: 3
old 6: b:=&b; new 6: b:=3;
4*1=4
4*2=8
4*3=12

Q8: Consider the EMPLOYEE (EMPNO, SALARY, ENAME) Table.


Write a procedure raise_sal which increases the salary of an employee. It accepts an employee
number and salary increase amount. It uses the employee number to find the current salary from
the EMPLOYEE table and update the salary.
PROGRAM:
//p3.sql
create or replace procedure raise_sal( mempno employee . empno % type,
msal_percent number ) as
begin
update employee set salary = salary + salary*msal_percent /100 where empno =

66
mempno; end;
/
//pq3.sql
declare
cursor c1 is select * from emp;
rec emp % rowtype;
begin
open c1;
loop
fetch c1 into rec;
exit when c1%notfound;
raisal(rec.empno,10);
end loop;
close
c1;
end;
/
SAMPLE OUTPUT:
SQL> @p3.sql;
Procedure created.

SQL> select * from emp;


EMPNO ENAME JOB DEPTNO SAL
---------- ----------- ------------ ------------- -----------
1 Manju AP 1 10000
2 Arav ASP 2 15000
3 Gowtham ASP 1 15000
4 Karthik Prof 2 30000
5 Anu AP 1 10000

SQL> @pq3.sql;

67
PL/SQL procedure successfully completed.

SQL> select * from emp;


EMPNO ENAME JOB DEPTNO SAL
---------- ------------ -------- ------------- ----------
1 Manju AP 1 11000
2 Arav ASP 2 16500
3 Gowtha ASP 1 16500
4 Karthik Prof 2 33000
5 Anu AP 1 11000

FUNCTIONS
Syntax:
create or replace function <function name> (argument in datatype,……) return datatype
{is,as} variable declaration;
constant declaration;
begin
PL/SQL subprogram body;
exception
exception
PL/SQL block;
end;

SETTING SERVERSAMPLE OUTPUT ON:


SQL> SET SERVERSAMPLE OUTPUT ON

TABLES USED:
SQL>select * from ittrain;
TNO TFARE
--------- ------------
1001 550
68
1002 600

Q1. Program to calculate the Train Fare using Function.

SQL> create function trainfn (trainnumber number) return number is


2 trainfunction ittrain.tfare % type;
3 begin
4 select tfare into trainfunction from ittrain where tno=trainnumber;
5 return(trainfunction);
6 end;
7 /
Function created.

SQL> declare
2 total number;
3 begin
4 total:=trainfn (1001);
5 dbms_Sample Output.put_line('Train fare is Rs. '||total);
6 end;
7 /

Sample Output:

Train fare is Rs.550


PL/SQL procedure successfully completed.

Q2. Program to calculate the Factorial of a Number Using Function

SQL> create function itfact (a number) return number is


2 fact number:=1;
3 b number;
4 begin
69
5 b:=a;
6 while b>0
7 loop
8 fact:=fact*b;
9 b:=b-1;
10 end loop;
11 return(fact);
12 end;
13 /

Function created.

SQL> declare
2 a number:=7;
3 f number(10);
4 begin
5 f:=itfact(a);
6 dbms_Sample Output.put_line(„The factorial of the given number is‟||f);
7 end;
8 /

The factorial of the given number is 5040

Q3: Write a PL/SQL function CheckDiv that takes two numbers as arguments and returns the
values 1 if the first argument passed to it is divisible by the second argument, else will return the
value 0;
PROGRAM:
//p.sql
create or replace function checkdiv (n1 number, n2 number) return number as
res number;
70
begin
if mod (n1, n2) = 0
then res := 1;
else
res:= 0;
end if;
return res;
end;
/
//pq4.sql
declare
a number;
b number;
begin
a:=&a; b:=&b; dbms_Sample
Output.put_line(„result=‟||checkdiv(a,b)); end;
/
SAMPLE OUTPUT:
SQL> @p4.sql;
Function created.

SQL> @pq4.sql;
Enter value for a: 4
old 5: a:=&a; new 5: a:=4;

Enter value for b: 2


old 6: b:=&b; new 6: b:=2;
result=1

Q4: Write a PL/SQL function called POW that takes two numbers as argument and return
the value of the first number raised to the power of the second .

71
PROGRAM:
//p5.sql
create or replace function pow (n1 number, n2 number) return number as
res number;
begin
select power ( n1, n2) into res from dual; return res; end;
or
create or replace function pow (n1 number, n2 number) return number as
res number : =1;
begin
for res in
1..n2 loop
res : = n1 * res;
end loop;
return res;
end;
//pq5.sql
declare
a number;
b number;
begin
a:=&a; b:=&b; dbms_Sample
Output.put_line('power(n1,n2)='||pow(a,b)); end;
/

SAMPLE OUTPUT:
SQL> @p5.sql;
Function created.

SQL> @ pq5.sql;
72
Enter value for a: 2
old 5: a:=&a; new
5: a:=2; Enter
value for b: 3 old
6: b:=&b; new 6:
b:=3;
power(n1,n2)=8

Q5: Write a PL/SQL function ODDEVEN to return value TRUE if the number passed to it
is EVEN else will return FALSE.
PROGRAM:
//p6.sql
create or replace function oddeven (n number) return boolean as
begin
if mod (n, 2) = 0 then return true;
else
return false;
end if;
end;
/
//pq6.sql
declare
a number; b boolean;
begin
a:=&a; b:=oddeven(a);
if b then
dbms_Sample Output.put_line('The given number
is Even'); else
dbms_Sample Output.put_line('The given number is Odd');
end if;
end;
73
/

SAMPLE OUTPUT:
SQL> @p6.sql;
Function created.

SQL> @pq6.sql;
Enter value for a: 5

old 5: a:=&a; new 5: a:=5;


The given number is Odd

74
EX.NO.6
Date:

CREATION OF TRIGGERS
AIM:
To create triggers for various events such as insertion, updation, etc.,

TRIGGER
A Trigger is a stored procedure that defines an action that the database automatically take
when some database-related event such as Insert, Update or Delete occur.

TYPES OF TRIGGERS
The various types of triggers are as follows,
 Before: It fires the trigger before executing the trigger statement.
After: It fires the trigger after executing the trigger statement.
For each row: It specifies that the trigger fires once per row.
 For each statement: This is the default trigger that is invoked. It specifies that the
trigger fires once per statement.

VARIABLES USED IN TRIGGERS


ew
ld
These two variables retain the new and old values of the column updated in the database.
The values in these variables can be used in the database triggers for data manipulation.

Syntax:
Create or replace trigger <trg_name> Before /After Insert/Update/Delete
[of column_name, column_name….]
on <table_name>
[for each row]
[when

75
condition] begin
---statement
end;
Q1: Create a trigger that insert current user into a username column of an existing table
PROCEDURE:
1 Create a table itstudent4 with name and username as arguments

2 Create a trigger for each row that insert the current user as user name into a table
3 Execute the trigger by inserting value into the table

PROGRAM:
SQL> create table itstudent4(name varchar2(15),username varchar2(15));
Table created.
SQL> create or replace trigger itstudent4 before insert on itstudent4 for each row
2 declare
3 name varchar2(20);
4 begin
5 select user into name from dual;
6 :new.username:=name;
7 end;
8 /
Trigger created.
SAMPLE
OUTPUT:

SQL> insert into itstudent4 values('&name','&username');


Enter value for name: akbar
Enter value for username: ranjani
old 1: insert into itstudent4 values('&name','&username')
new 1: insert into itstudent4 values('akbar','ranjani')
1 row created.

76
SQL> /
Enter value for name: suji
Enter value for username: priya
old 1: insert into itstudent4 values('&name','&username')
new 1: insert into itstudent4 values('suji','priya')
1 row created.
SQL> select * from itstudent4;

NAME USERNAME
--------------- ---------------
akbar SCOTT
suji SCOTT

Q2: Create a Simple Trigger that does not allow Insert Update and Delete Operations on
the Table
PROGRAM:

Table used:
SQL> select * from itempls;
ENAME EID SALARY
---------- --------- ---------
xxx 11 10000
yyy 12 10500
zzz 13 15500

TRIGGER
SQL> create trigger ittrigg before insert or update or delete on itempls for each row
2 begin
3 raise_application_error(-20010,'You cannot do manipulation');
4 end;
5 /
Trigger created.

77
SAMPLE OUTPUT:
SQL> insert into itempls values('aaa',14,34000);
insert into itempls values('aaa',14,34000)
*
ERROR at line 1:
ORA-20010: You cannot do manipulation
ORA-06512: at "STUDENT.ITTRIGG", line 2
ORA-04088: error during execution of trigger 'STUDENT.ITTRIGG'

SQL> delete from itempls where ename='xxx'; delete from


itempls where ename='xxx'
*
ERROR at line 1:
ORA-20010: You cannot do manipulation
ORA-06512: at "STUDENT.ITTRIGG", line 2
ORA-04088: error during execution of trigger 'STUDENT.ITTRIGG'

SQL> update itempls set eid=15 where ename='yyy';


update itempls set eid=15 where ename='yyy'
*
ERROR at line 1:
ORA-20010: You cannot do manipulation
ORA-06512: at "STUDENT.ITTRIGG", line 2
ORA-04088: error during execution of trigger 'STUDENT.ITTRIGG'

Q3: Create a Trigger that raises an User Defined Error Message and does not allow
updating and Insertion
PROGRAM:

Table used:
SQL> select * from itempls;

78
ENAME EID SALARY
---------- --------- ---------
xxx 11 10000
yyy 12 10500
zzz 13 15500

TRIGGER:
SQL> create trigger ittriggs before insert or update of salary on itempls for each row
2 declare
3 triggsal itempls.salary%type;
4 begin
5 select salary into triggsal from itempls where eid=12;
6 if(:new.salary>triggsal or :new.salary<triggsal) then
7 raise_application_error(-20100,'Salary has not been changed');
8 end if;
9 end;
10 /
Trigger created.

SAMPLE OUTPUT:

SQL> insert into itempls values ('bbb',16,45000);

insert into itempls values ('bbb',16,45000)


*
ERROR at line 1:
ORA-04098: trigger 'STUDENT.ITTRIGGS' is invalid and failed re-validation

SQL> update itempls set eid=18 where ename='zzz';

update itempls set eid=18 where ename='zzz'

79
*
ERROR at line 1:
ORA-04298: trigger 'STUDENT.ITTRIGGS' is invalid and failed re-validation

Q4: Develop a query to Drop the Created Trigger


PROGRAM:
SQL> drop trigger ittrigg;
Trigger dropped.

80
EX.NO.7
Date:

EXCEPTION HANDLING
AIM:
To create a PL/SQL program for exception handling.

PL/SQL - EXCEPTIONS

 An error condition during a program execution is called an exception in PL/SQL.


PL/SQL supports programmers to catch such conditions using EXCEPTION block in the
program and an appropriate action is taken against the error condition.
 There are two types of exceptions:

1.System-defined exceptions

2.User-defined exceptions

Syntax:
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2 THEN
exception2-handling-statements
WHEN exception3 THEN
exception3-handling-statements
........
WHEN others THEN
exception3-handling-statements

81
END;

Q1 . Program For System defined Exception Handling.


TABLES USED:

SQL > select * from customer;

ID NAME ADDRESS
---------- ----------------- ------------------
1 Arun Kalyan Nagar
2 Vijay Fifth cross

PROGRAM:

DECLARE
c_id customer.id%type := 8;
c_name customer.name%type;
c_addr customer.address%type;
BEGIN
SELECT name, address INTO c_name, c_addr
FROM customer
WHERE id = c_id;
DBMS_SAMPLE OUTPUT.PUT_LINE ('Name: '|| c_name);
DBMS_SAMPLE OUTPUT.PUT_LINE ('Address: ' || c_addr);
EXCEPTION
WHEN no_data_found THEN
dbms_Sample Output.put_line('No such customer!');
WHEN others THEN
dbms_Sample Output.put_line('Error!');
END;
/
OUPTUT:
No such customer!
PL/SQL procedure successfully completed.

82
Q2 . Program for User defined Exception Handling.

DECLARE
c_id customers.id%type := &cc_id;
c_name customers.name%type;
c_addr customers.address%type;
-- user defined exception
ex_invalid_id EXCEPTION;
BEGIN
IF c_id <= 0 THEN
RAISE ex_invalid_id;
ELSE
SELECT name, address INTO c_name, c_addr
FROM customers
WHERE id = c_id;
DBMS_SAMPLE OUTPUT.PUT_LINE ('Name: '|| c_name);
DBMS_SAMPLE OUTPUT.PUT_LINE ('Address: ' || c_addr);
END IF;
EXCEPTION
WHEN ex_invalid_id THEN
dbms_Sample Output.put_line('ID must be greater than zero!');
WHEN no_data_found THEN
dbms_Sample Output.put_line('No such customer!');
WHEN others THEN
dbms_Sample Output.put_line('Error!');
END;
/

SAMPLE OUTPUT:

Enter value for cc_id: -6 (let's enter a value -6)

83
old 2: c_id customers.id%type := &cc_id;
new 2: c_id customers.id%type := -6;
ID must be greater than zero!

PL/SQL procedure successfully completed.

84
EX.NO:8
Date:

DATABASE DESIGN USING E-R MODEL AND NORMALIZATION AND


IMPLEMENTATION OF ANY APPLICATION

ENTITY-RELATIONSHIP MODEL (ER MODEL)


 The entity-relationship (ER) data model was developed to facilitate database design by
allowing specification of an enterprise schema that represents the overall logical structure
of a database.
 The E-R model is very useful in mapping the meanings and interactions of real-world
enterprises onto a conceptual schema.
 The E-R model represent three main components
o Entities
o Attributes
o Relationships
Entity
 An Entity is a “thing” or “object” in the real world that is distinguishable from
other object.
Attributes
 An attribute is a property that describes the aspects of the object.
 Each entity has a value for each of its attributes.

EMPLOYEE DATABASE
1.CREATE EMPLOYEE TABLE
SQL> CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot NUMBER(20),
PRIMARY KEY (ssn) )

Table Created.

SQL> INSERT INTO EMPLOYEE VALUES(„&SSN‟,‟&NAME‟,&LOT);


85
Enter value for SSN: 1
Enter value for NAME: A
Enter value for LOT: 100
old 1: insert into employee values(„&SSN‟,‟&NAME‟,&LOT);
new 1: insert into emp values(1,‟A‟,100)
1 row created.

SQL> /
Enter value for SSN: 2
Enter value for NAME: B
Enter value for LOT: 200
old 1: insert into employee values(„&SSN‟,‟&NAME‟,&LOT);
new 1: insert into emp values(2,‟B‟,200)
1 row created.

SQL> /
Enter value for SSN: 3
Enter value for NAME: C
Enter value for LOT: 300
old 1: insert into employee values(„&SSN‟,‟&NAME‟,&LOT);
new 1: insert into emp values(3,‟C‟,300)
1 row created.

SQL> /
Enter value for SSN: 4
Enter value for NAME: D
Enter value for LOT: 400
old 1: insert into employee values(„&SSN‟,‟&NAME‟,&LOT);
new 1: insert into emp values(4,‟D‟,400)
1 row created.

SQL> select * from employee;

SSN NAME LOT


---------- --------------------- ---------------
1 A 100
2 B 200
3 C 300
4 D 400

2.CREATE DEPARTMENT TABLE


86
SQL> CREATE TABLE Department (did char(10), dname char(20),budget
number(20),PRIMARY KEY (did) );
Table Created.

SQL> INSERT INTO DEPARTMENT VALUES(„&DID‟,‟&DNAME‟,&BUDGET);


Enter value for DID: 10
Enter value for DNAME: SALES
Enter value for BUDGET: 10000
old 1: insert into employee values („&DID‟,‟&DNAME‟,&BUDGET);
new 1: insert into emp values(10,‟SALES‟,10000)
1 row created.

SQL> /
Enter value for DID: 15
Enter value for DNAME: ACCOUNTING
Enter value for BUDGET: 20000
old 1: insert into employee values („&DID‟,‟&DNAME‟,&BUDGET);
new 1: insert into emp values(15,‟ACCOUNTING‟,20000)
1 row created.

SQL> /
Enter value for DID: 20
Enter value for DNAME: IT
Enter value for BUDGET: 30000
old 1: insert into employee values („&DID‟,‟&DNAME‟,&BUDGET);
new 1: insert into emp values(20,‟IT‟,30000)
1 row created.

SQL> select * from department;

DID DNAME BUDGET


---------- --------------------- ---------------
10 SALES 10000
15 ACCOUNTING 20000
20 IT 30000

87
E-R DIAGRAM FOR EMPLOYEE TABLE

Relationship
 A relationship is an association between several entities.
Relationship Set
 It is a set of relationships of the same type.

3.CREATE WORKS-IN RELATION

SQL> CREATE TABLE Works_In (ssn CHAR(1), did NUMBER(20), since DATE, PRIMARY
KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employee, FOREIGN KEY (did)
REFERENCES Department)

SQL> SELECT * FROM WORKS_IN

88
 Relationship sets can also have descriptive attributes (e.g., the since attribute of
Works_In).
 In translating a relationship set to a relation, attributes of the relation must
include:
 Keys for each participating entity set (as foreign keys).This set of attributes
forms superkey for the relation.
 All descriptive attributes.
CONSTRAINTS
An E-R enterprise schema may define certain constraints to which the contents of a database
must conform.
1. Mapping Cardinalities
2. Key Constraints
3. Participation Constraints

KEY CONSTRAINTS
 Consider Works_In: An employee can work in many departments; a dept can have many
employees.
 In contrast, each dept has at most one manager, according to the key constraint on
Manages.

SQL> CREATE TABLE Manages (ssn CHAR(10), did number(20), since DATE, PRIMARY
KEY (did), FOREIGN KEY (ssn) REFERENCES Employee, FOREIGN KEY (did)
REFERENCES Department)

PARTICIPATION CONSTRAINTS
89
 Every department have a manager is a participation constraint: the participation of
Departments in Manages is said to be total (vs. partial).
 Every did value in Departments table must appear in a row of the Manages table (with a
non-null ssn value!)

SQL> CREATE TABLE Dept_Mgr (did number(20) UNIQUE, dname varchar(20),budget


number(20) CHECK budget>10000,ssn varchar(10) NOT NULL, since DATE, PRIMARY KEY
(did), FOREIGN KEY (ssn) REFERENCES Employee, FOREIGN KEY (did) REFERENCES
Department)

NORMALIZATION
1.FIRST NORMAL FORM

The First normal form (1NF) sets basic rules for an organized database −

 Define the data items required, because they become the columns in a table.

 Place the related data items in a table.

 Ensure that there are no repeating groups of data.

 Ensure that there is a primary key.

CREATE CUSTOMER TABLE


90
CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25),
ORDERS VARCHAR(155)
);

ID NAME AGE ADDRESS ORDERS

100 Sachin 36 Lower West Side Cannon XL-200

100 Sachin 36 Lower West Side Battery XL-200

100 Sachin 36 Lower West Side Tripod Large

But as per the 1NF, we need to ensure that there are no repeating groups of data. So, let us break
the above table into two parts and then join them using a key as shown in the following program

CUSTOMERS table
CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25),
PRIMARY KEY (ID)
);
This table would have the following record −
ID NAME AGE ADDRESS

100 Sachin 36 Lower West Side

ORDERS table
CREATE TABLE ORDERS(
ID INT NOT NULL,
CUSTOMER_ID INT NOT NULL,
ORDERS VARCHAR(155),
PRIMARY KEY (ID)
);
This table would have the following records −
91
ID CUSTOMER_ID ORDERS

10 100 Cannon XL-200

11 100 Battery XL-200

12 100 Tripod Large

2.SECOND NORMAL FORM

The Second Normal Form states that it should meet all the rules for 1NF and there must be no
partial dependences of any of the columns on the primary key −

Consider a customer-order relation and you want to store customer ID, customer name, order ID
and order detail and the date of purchase −
CREATE TABLE CUSTOMERS(
CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
ORDER_ID INT NOT NULL,
ORDER_DETAIL VARCHAR (20) NOT NULL,
SALE_DATE DATETIME,
PRIMARY KEY (CUST_ID, ORDER_ID)
);
 This table is in the first normal form; in that it obeys all the rules of the first normal
form. In this table, the primary key consists of the CUST_ID and the ORDER_ID.
 However, the table is not in the second normal form because there are partial
dependencies of primary keys and columns. CUST_NAME is dependent on CUST_ID
 The order detail and purchase date are also dependent on the ORDER_ID, but they are
not dependent on the CUST_ID, because there is no link between a CUST_ID and an
ORDER_DETAIL or their SALE_DATE.
 To make this table comply with the second normal form, you need to separate the
columns into three tables.

First, create a table to store the customer details as shown in the code block below −
CREATE TABLE CUSTOMERS(
CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
PRIMARY KEY (CUST_ID)
);
The next step is to create a table to store the details of each order −
92
CREATE TABLE ORDERS(
ORDER_ID INT NOT NULL,
ORDER_DETAIL VARCHAR (20) NOT NULL,
PRIMARY KEY (ORDER_ID)
);
Finally, create a third table storing just the CUST_ID and the ORDER_ID to keep a track of all
the orders for a customer −
CREATE TABLE CUSTMERORDERS(
CUST_ID INT NOT NULL,
ORDER_ID INT NOT NULL,
SALE_DATE DATETIME,
PRIMARY KEY (CUST_ID, ORDER_ID)
);

THIRD NORMAL FORM


A table is in a third normal form when the following conditions are met −

 It is in second normal form.


 All non-primary fields are dependent on the primary key.

CREATE TABLE CUSTOMERS(


CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
DOB DATE,
STREET VARCHAR(200),
CITY VARCHAR(100),
STATE VARCHAR(100),
ZIP VARCHAR(12),
EMAIL_ID VARCHAR(256),
PRIMARY KEY (CUST_ID)
);

 The dependency between the zip code and the address is called as a transitive
dependency.
 To comply with the third normal form, all you need to do is to move the Street, City and
the State fields into their own table, which you can call as the Zip Code table.

CREATE TABLE ADDRESS(


ZIP VARCHAR(12),
STREET VARCHAR(200),
CITY VARCHAR(100),
STATE VARCHAR(100),
PRIMARY KEY (ZIP)
);

93
The next step is to alter the CUSTOMERS table as shown below −
CREATE TABLE CUSTOMERS(
CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
DOB DATE,
ZIP VARCHAR(12),
EMAIL_ID VARCHAR(256),
PRIMARY KEY (CUST_ID)
);

94
EX.NO.9
Date:

DATABASE CONNECTIVITY WITH FRONT END TOOLS


Aim:
To connect database with front end tools to design forms and reports.

Examples Front End Tools:


a. Visual Basic
b. Visual C++
c. Java
d. PHP
e. HTML

1. MICROSOFT VISUAL BASIC:


 Visual Basic (VB) is the third-generation event-driven programming language and
integrated development environment (IDE) from Microsoft for its COM programming
model.
 Visual Basic is relatively easy to learn and use.
 Visual Basic was derived from BASIC and enables the rapid application development
(RAD) of graphical user interface (GUI) applications, access to databases using Data
Access Objects, Remote Data Objects, or ActiveX Data Objects, and creation of ActiveX
controls and objects.
 Scripting languages such as VBA and VBScript are syntactically similar to Visual Basic,
but perform differently.
 A programmer can put together an application using the components provided with
Visual Basic itself. Programs written in Visual Basic can also use the Windows API, but
doing so requires external function declarations.
1.1 Language features
 Like the BASIC programming language, Visual Basic was designed to be easily learned
and used by beginner programmers.
95
 The language not only allows programmers to create simple GUI applications, but can
also develop complex applications.
 Programming in VB is a combination of visually arranging components or controls on a
form, specifying attributes and actions of those components, and writing additional lines
of code for more functionality.
 Since default attributes and actions are defined for the components, a simple program can
be created without the programmer having to write many lines of code.
 Forms are created using drag-and-drop techniques. A tool is used to place controls (e.g.,
text boxes, buttons, etc.) on the form (window).
 Controls have attributes and event handlers associated with them.
 Default values are provided when the control is created, but may be changed by the
programmer.
 Many attribute values can be modified during run time based on user actions or changes
in the environment, providing a dynamic application.
 By inserting code into the event handler for a key press in a text box, the program can
automatically translate the case of the text being entered, or even prevent certain
characters from being inserted.
 Visual Basic can create executables (EXE files), ActiveX controls, or DLL files, but is
primarily used to develop Windows applications and to interface database systems.
 Dialog boxes with less functionality can be used to provide pop-up capabilities. Controls
provide the basic functionality of the application, while programmers can insert
additional logic within the appropriate event handlers.
 An event handler is called when an item is selected, which can then execute additional
code created by the programmer to perform some action based on which element was
selected, such as populating a related list.
 Alternatively, a Visual Basic component can have no user interface, and instead provide
ActiveX objects to other programs via Component Object Model (COM). This allows for
server-side processing or an add-in module.
2. MICROSOFT VISUAL C++

96
 Microsoft Visual C++ (often abbreviated as MSVC or VC++) is a commercial (free
version available), integrated development environment (IDE) product from Microsoft
for the C, C++, and C++/CLI programming languages.
 It has tools for developing and debugging C++ code, especially code written for the
Microsoft Windows API, the DirectX API, and the Microsoft .NET Framework.
3. JAVA

 Java is a programming language originally developed by James Gosling at Sun


Microsystems (now part of Oracle Corporation) and released in 1995 as a core
component of Sun Microsystems' Java platform.
 The language derives much of its syntax from C and C++ but has a simpler object model
and fewer low-level facilities.
 Java applications are typically compiled to byte code (class file) that can run on any Java
Virtual Machine (JVM) regardless of computer architecture.
 Java is a general-purpose, concurrent, class-based, object-oriented language that is
specifically designed to have as few implementation dependencies as possible.
 It is intended to let application developers "write once, run anywhere."
 Java is currently one of the most popular programming languages in use, particularly for
client-server web applications.
There were five primary goals in the creation of the Java language:
1. It should be "simple, object-oriented and familiar"
2. It should be "robust and secure"
3. It should be "architecture-neutral and portable"
4. It should execute with "high performance"
5. It should be "interpreted, threaded, and dynamic"
4.HTML
HTML is a language for describing web pages.
• HTML stands for Hyper Text Markup Language
• HTML is not a programming language, it is a markup language
• A markup language is a set of markup tags
• HTML uses markup tags to describe web pages

97
4.1 HTML Documents = Web Pages
• HTML documents describe web pages
• HTML documents contain HTML tags and plain text
• HTML documents are also called web pages
 The purpose of a web browser (like Internet Explorer or Firefox) is to read HTML
documents and display them as web pages.
 The browser does not display the HTML tags, but uses the tags to interpret the content of
the page:
4.2 Editing HTML
 HTML can be written and edited using many different editors like Dreamweaver and
Visual Studio.
 However, in this tutorial we use a plain text editor (like Notepad) to edit HTML.
 Using a plain text editor is the best way to learn HTML.

STUDENT INFORMATION FORM

SQL> create table stuinfo(name varchar2(15),dept varchar2(6),mark1 number(2),mark2


number(2),mark3 number(2),gender varchar(20),address varchar(20),total number(3),avg
number(4),grade varchar2(2));

Table created.

SQL> desc stuinfo;

Name Null? Type


-------------------- ----------- ------------
NAME VARCHAR2 (15)
DEPT VARCHAR2(6)
MARK1 NUMBER(2)
MARK2 NUMBER(2)
MARK3 NUMBER(2)
GENDER VARCHAR(20)
ADDRESS VARCHAR(20)
TOTAL NUMBER(3)
98
AVG NUMBER(4)
GRADE VARCHAR2(2)

SQL> insert into stuinfo


values('&sname','&dept','&mark1','&mark2','&mark3',‟&gender‟,‟&address‟,'&total','&avg','&gr
ade');
Enter value for sname: Bharathi
Enter value for dept: it
Enter value for mark1: 67
Enter value for mark2: 78
Enter value for mark3: 67
Enter value for gender: M
Enter value for address: Kalyan nagar
Enter value for total: 134
Enter value for avg: 69
Enter value for grade: b
old 1: insert into stuinfo
values('&sname','&dept','&mark1','&mark2','&mark3','&total','&avg','&gr
new 1: insert into stuinfo values('sudha','it','67','78','67','134','69','b')

1 row created.

SQL> /
Enter value for sname:Hari
Enter value for dept: cse
Enter value for mark1: 76
Enter value for mark2: 75
Enter value for mark3: 74
Enter value for gender: M
Enter value for address: North Street
Enter value for total: 279
Enter value for avg: 77
Enter value for grade: a
old 1: insert into stuinfo
values('&sname','&dept','&mark1','&mark2','&mark3','&total','&avg','&gr
new 1: insert into stuinfo values('rama','cse','76','75','74','279','77','a')

SQL> select * from stuinfo;

SNAME DEPT MARK1 MARK2 MARK3 GENDER ADDRESS TOTAL AVG GRADE
99
--------------- ------------- --------- --------- ------------ --------- ------------ ----------- ------ ------------
Bharathi IT 67 78 67 M Kalyan nagar 134 69 B
Hari CSE 76 75 74 M North street 279 77 A

To Calculate the total:


ITEM NAME :total
TRIGGERNAME :When_mouse_click

begin
:stuinfo.total:=:stuinfo.mark1+:stuinfo.mark2+:stuinfo.mark3;
end;

To Find the Average:


ITEM NAME :AVG
TRIGGERNAME :When_mouse_click

begin
:stuinfo.avg:=(:stuinfo.total/3);
end;

To Find Grade:
ITEM NAME :GRADE
TRIGGERNAME :When_mouse_click

begin
if :stuinfo.mark1>35 and :stuinfo.mark2>35 then
if :stuinfo.avg>80 then
:stuinfo.grade:='A';
else
:stuinfo.grade:='B';
end if;
else
:stuinfo.grade:='C';
end if;
end;

To Append:
ITEM NAME : APPEND
TRIGGERNAME : When_mouse_click

100
begin
create_record;
end;

To Delete:
ITEM NAME : DELETE
TRIGGERNAME : When_mouse_click

begin
delete_record;
end;

To Save the Record:


ITEM NAME :SAVE
TRIGGERNAME : When_mouse_click

begin
commit_form;
end;

To Exit:
ITEM NAME : EXIT
TRIGGERNAME : When_mouse_click

begin
exit_form;
end;

To Clear:
ITEM NAME : CLEAR
TRIGGERNAME : When_mouse_click

begin
clear_form;
end;

SQL> select * from stuinfo;

SNAME DEPT MARK1 MARK2 MARK3 GENDER ADDRESS TOTAL AVG GRADE
--------------- ------------- --------- --------- ------------ --------- ------------ ---------- -------- -----------
101
Bharathi IT 67 78 67 M Kalyan nagar 134 69 B
Hari CSE 76 75 74 M North street 279 77 A
Sudhakar IT 89 76 67 M East street 232 77 A
Ramarajan CSE 65 54 60 M First cross 179 59 C
FORM CODING

LOGIN FORM

Dim Con As New ADODB.Connection


Dim Rs As New ADODB.Recordset

Private Sub Command1_Click()


Text1.Text = ABC
Text2.Text = BCA
Form2.Show
End Sub

Private Sub Command2_Click(


End
End Sub

STUDENT INFORMATION FORM

Dim Con As New ADODB.Connection


Dim Rs As New ADODB.Recordset

Private Sub Command6_Click()


End
End Sub

Private Sub Delete_Click()


Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion
Confirmation")
If Confirm = vbYes The
Adodc1.Recordset.Delete
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
End Sub

102
Private Sub insert_Click()
Adodc1.Recordset.AddNew
End Sub
Private Sub movefirst_Click()
Adodc1.Recordset.movefirst
End Sub

Private Sub movelast_Click()


Adodc1.Recordset.movelast
End Sub

Private Sub Text10_LostFocus()


If Val(Text9.Text) >= 70 Then
Text10.Text = "A"
Else
If (Val(Text9.Text) >= 60 & Val(Text9.Text) < 70) Then
Text10.Text = "B"
Else
If (Val(Text9.Text) >= 50 & Val(Text9.Text) < 60) Then
Text10.Text = "C"
Else
If Val(Text9.Text) <= 49 Then
Text10.Text = "D"
End If
End If
End If
End If
End Sub

Private Sub Text8_LostFocus()


Text8.Text = Val(Text3.Text) + Val(Text4.Text) + Val(Text5.Text)
End Sub

Private Sub Text9_LostFocus()


Text9.Text = Val(Text8.Text) / 3
End Sub

103
FORM DESIGN

104
SAMPLE OUTPUT

105
REPORT GENERATION

106
107
108
109
110
111
112
113
EX.NO:10
Date:

CASE STUDY USING REAL LIFE DATABASE APPLICATIONS

DATABASE APPLICATIONS
 Database applications are software programs designed to collect, manage and disseminate
information efficiently.
 Many home and small business owners create simple databases such as customer contact
and mailing lists with easy to use software such as Microsoft "Access" and "FileMaker
Pro." "Oracle," "SQL Server," and "FoxPro" are examples of advanced database
applications with programming languages that can be used to build custom business
solutions in networked environments.

PURPOSE OF DATABASE APPLICATIONS


 Database applications are used to search, sort, calculate, report and share information.
 Databases can also contain code to perform mathematical and statistical calculations on
the data to support queries submitted by users.
 Database applications provide security by restricting access to data based upon user
names and passwords. Most database applications are customized with a database
programming language to automate specific types of work.

HISTORY OF DATABASE APPLICATIONS

1. Data processing drove growth of computer processor speed.Punched cards were used in
the US for collecting data for census during beginning of 20th century. Earliest data
processing was done by punched cards on mechanical devices. The real development in
data processing speed, storage of data and development of DB applications started much
later i.e. from 1950s.
2. Magnetic tapes were used to store data and being read from it. These database
applications had hierarchical structure and used network systems. They were extremely
efficient when used with the original query, exactly developed for them, but the DB was
not designed to handle new queries or transactions. Also the magnetic tapes must be in
same sorted order so as to retrieve the authentic data.
3. Later in 60s Hard Disks came about and data retrieval was faster and did not need be
stored sequentially. This period was also remarkable in terms of advancement in DB
Systems.
4. Later in 1970 Edgar Codd, father or Relational Database Model, conceptualized a new
structure for Database construction and wrote a groundbreaking paper „A Relational
Model of Data for Large Shared Data Banks‟. He freed database from procedural ways of
querying and marked the beginning of Data Abstraction i.e. hiding details of how
Database is implemented to application programmers and end users. System R, based on
Codd‟s concept was developed by IBM and it was first to have a language for querying
called SQL or Structured Query Language.

114
5. Later, System R was further developed to a mainstream commercial DBMS product
known as DB2.
6. Object oriented programming was rapidly developing in the 80s and it also helped
break into what we know as Object Oriented Databases. The idea was to treat data as
objects and it became easier to conceptualize and program using this idea. Another great
development which happened was processing speed of processors and also
conceptualization of indexing which greatly increased data access times, and
performances of DB.
7. 90s was a time of a World Wide Web, so unprecedented like world had never seen
before. The data was here on the internet. Databases to which links were forwarded were
varied and different and it needed a technique to interchange data efficiently. Also the
database had to be of very high availability working 24x7.
8. XML or Extended Markup Language is a standard for providing data exchange among
different databases and WebPages.
9. More recently, there has been a growing trend of NoSQL database. These are different
from so called classical databases and do not rely on Relational Model for their structure.
They do not query data using Structured Query Language but UnQL or Unstructured
Query Language which is still in development stage (it is similar to XQuery).

TYPES OF DATABASES

 There are several types of databases that can be used in real-world scenarios.

 Flat-file databases are generally plain text files that can be used by local applications to
store data. Flat files are not as popular as relational databases.

 Relational database are databases with related tables of information. Each table has a
number of columns or attributes and a set of records or rows. Relational databases are
popular because of their scalability, performance and ease of use.

BENEFITS OF DATABASES

1. Databases are stored digitally, multiple users in different locations can view the data in
more than once place. Banks store their customer information and balances in a database,
so can use any branch for deposits and withdrawals.

2. Databases allow more flexibility because they are in a digital format. Companies use
databases for inventory and item pricing. A retail chain can see when stores are low in
inventory and automatically order more. Prices can be updated across the country
instantly as compared to having to manually do it at each store.

3. Databases are used to distribute data quickly and easily because they are only updated
once and can be read by many users.

APPLICATIONS OF DATABASE MANAGEMENT SYSTEM (DBMS):

115
 Due the evolution of Database management system, companies are getting more from
their work because they can keep records of everything.
 Also it makes them faster to search information and records about any people or product
that makes them more effective in work.

1.Railway Reservation System


 Database is required to keep record of ticket booking, train‟s departure and arrival status.
Also if trains get late then people get to know it through database update.

2.Library Management System


 There are thousands of books in the library so it is very difficult to keep record of all the
books in a copy or register. So DBMS used to maintain all the information relate to book
issue dates, name of the book, author and availability of the book.

3.Banking
 We make thousands of transactions through banks daily and we can do this without going
to the bank. So how banking has become so easy that by sitting at home we can send or
get money through banks. That is all possible just because of DBMS that manages all the
bank transactions.

4.Universities and colleges


 Examinations are done online today and universities and colleges maintain all these
records through DBMS. Student‟s registrations details, results, courses and grades all the
information are stored in database.

5.Credit card transactions


 For purchase of credit cards and all the other transactions are made possible only by
DBMS. A credit card holder knows the importance of their information that all are
secured through DBMS
6.Accounting Applications

 An accounting system is a custom database application used to manage financial data.


Custom forms are used to record assets, liabilities, inventory and the transactions between
customers and suppliers. The income statements, balance sheets, purchase orders and
invoices generated are custom reports based upon information that is entered into the
database.

116
 "Microsoft Money," "Quicken," "QuickBooks" and "Peachtree" are accounting systems
built upon database applications.

7.CRM Applications
 A customer relationship management system (CRM) is to manage the marketing, sales,
and support relationships between a business and it's customers. The ultimate goal is to
maximize sales, minimize costs and foster strategic customer relationships.
 "SAP," "Salesforce.com," and Oracle's "Siebel" are robust CRM database applications
suitable for larger enterprises.

8.Web Applications
 Many contemporary web sites are built using several database applications
simultaneously as core components.
 Most retail store Web sites including "Bestbuy.com," and "Amazon.com" use database
systems to store, update and present data about products for sale. These Web sites also
combine an accounting database system to record sales transactions and a CRM database
application to incorporate feedback and drive a positive customer experience.
 The popular Web-based "Facebook" application is essentially a database built upon the
"MySQL" database system and is an indication of the increasing usage of database
applications as foundations for Web-based applications.

9.Telecom:

 There is a database to keeps track of the information regarding calls made, network
usage, customer details etc. Without the database systems it is hard to maintain that huge
amount of data that keeps updating every millisecond.

10.Industry:

 Where it is a manufacturing unit, warehouse or distribution centre, each one needs a


database to keep the records of ins and outs. For example distribution centre should keep
a track of the product units that supplied into the centre as well as the products that got
delivered out from the distribution centre on each day; this is where DBMS comes into
picture.

11.Airlines:

 To travel though airlines, we make early reservations, this reservation information along
with flight schedule is stored in database.

12. Online shopping:

117
 The online shopping websites such as Amazon, Flipkart etc., store the product
information, your addresses and preferences, credit details and provide you the relevant
list of products based on your query. All this involves a Database management system.

118

You might also like