You are on page 1of 102

211719104072

RAJALAKSHMI INSTITUTE OF TECHNOLOGY

KUTHAMBAKAM, CHENNAI – 600 124

Laboratory Record Note Book

NAME : MADHULIKA INDRAGANTI

SUBJECT CODE/TITLE : CS8481

Database management systems laboratory

BRANCH : Computer Science and Engineering

UNIVERSITY REGISTER NO : 211719104072

COLLEGE ROLL NO 201901071

SEMESTER IV

ACADEMIC YEAR :2020-2021

1
211719104072

RAJALAKSHMI INSTITUTE OF
TECHNOLOGY
KUTHAMBAKKAM, CHENNAI-600124.

BONAFIDE CERTIFICATE

NAME: MADHULIKAINDRAGANTI

ACADEMIC YEAR : 2020-2021

SEMESTER IV

BRANCH : CSE

UNIVERSITY REGISTER NO : 211719104072

Certified that this is a bonafide record of work done by the above student in
the

CS8481 – Database Management Systems Laboratory during the academic


year 2020-2021.

Submitted for the Practical Examination held on ………………………

Head of the Department Signature of Faculty-in-charge

Internal Examiner External Examiner

2
211719104072

INDEX
Name: MADHULIKA INDRAGANTI Sec: B

Branch: Computer Science and Engineering Roll No: 201901071

S.NO DATE TITLE PG.NO

1 19-02-2021 Data definition and Data manipulation commands 4

2 26-02-2021 Data querying-Simple and nested queries 10

VIEWS,SEQUENCES,SYNONYMS AND SUB QUERIES

3a 05-03-2021 Views 18

3b 05-03-2021 Sequences 21

3c 05-03-2021 Synonyms 23

DATABASE PROGRAMMING

4a 12-03-2021 Implicit cursers 24

4b 12-03-2021 Explicit cursers 26

PROCEDURES AND FUNCTIONS

5a 19-03-2021 Procedures 28

5b 19-03-2021 Functions 32

6 20-03-2021 Triggers 36

7 26-03-2021 Exception handling 39

8 09-04-2021 Database design using FR modeling normalization and 44


application

9 16-04-2021 Database connectivity with front end tools 49

10 23-04-2021 Case study using real life database application 68

CONTENT BEYOND SYLLABUS

11 30-04-2021 Distributed database 74

12 07-05-2021 Deadlock detection algorithm for distributed databse 87


using wait-for graph

3
211719104072

EX.NO: 1 DATA DEFINITION AND DATA MANIPULATION COMMANDS

DATE : 19-02-2021

AIM:
To create table and implement data definition and data manipulation commands in SQL

DESCRIPTION:

DATA DEFINITION LANGUAGE:

The Data Definition Language (DDL) is used to

Creating a table
Altering table structure by adding, deleting or modifying columns
Destroy databases and database objects.
These commands will primarily be used by database administrators during the setup and removal
phases of a database project.

Data Retrieval: Select


Data Manipulation Language (DML): Insert, Delete, Update
Transaction Control Language(TCL):Commit, Save Point, Rollback

THE ORACLE TABLE – DUAL - Dual is a small oracle table which consists of only
onerow and one column and contains the value X in that column.

INSERT -This command is used to insert values into the table.

SELECT - This command is used to display the contents of the table or those of
aparticular column.

UPDATE-A SQL UPDATE statement that changes the data of one or more records in
atable. Either all the rows can be updated, or a subset may be chosen using a condition

DELETE -An SQL DELETE statement removes one or more records from a table.
Asubset may be defined for deletion using a condition, otherwise all records are removed

RENAME - This command renames the name of the table.

COMMIT - This command is used to permanently stored the data in the database.

ROLLBACK - This command restores the database to last committed state.

SAVEPOINT - This command is used to temporarily save a transaction so that user


canrollback to the point whenever required.

4
211719104072

CREATE TABLE COMMANDS:

SQL> create table stud (snamevarchar2(30), sid varchar2(10), sage number(2), sarea
varchar2(20));
Table created.

SQL>desc stud;

NameNull? Type

SNAMENullVARCHAR2(30)
SIDNullVARCHAR2(10)
SAGENullNUMBER(2)
SAREANullVARCHAR2(20)

ALTER TABLE

SQL>alter table stud modify ( sage number(10));

Table altered.

SQL>desc stud;

NameNull? Type

SNAME Null VARCHAR2(30)


SIDNull VARCHAR2(10)
SAGE Null NUMBER(10)
SAREANull VARCHAR2(20)

SQL> alter table stud add ( sdept varchar2(20));

Table altered.

SQL>desc stud;

NameNull? Type

SNAME null VARCHAR2(30)


SID VARCHAR2(10)
SAGE NUMBER(10)

5
211719104072

SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)

SQL> alter table stud drop (sdeptvarchar2(20));

Table altered.

SQL>desc studs;
NameNull? Type

SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)

TRUNCATE TABLE:
TRUNCATE TABLE removes all rows from a table, but the table structure and its columns,
constraints, indexes and so on remain.
SQL> truncate table studs;

Table truncated.

SQL>desc studs

NameNull? Type

SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)

DROP TABLE:

Drop table removes one or more table definitions completely from the database,by removing
all data, indexes, triggers, constraints, and permission specifications for those tables.
SQL> drop table studs;

Table dropped.

6
211719104072

CREATION OF TABLE

SQL>create table stud (snamevarchar2(30), sid varchar2(10), sage number(10), sarea


varchar2(20), sdept varchar2(20));
Table created.

INSERTION OF VALUES INTO THE TABLE:

SYNTAX:

INSERT INTOtable (column1, [column2, ... ]) VALUES (value1, [value2, ...])

INSERT INTOtableVALUES (value1, [value2, ...])

SQL> insert into stud values ('ashwin',101,19,'anna nagar','aeronautical');

1 row created.

SQL> insert into stud values ('bhavesh',102,18,'nungambakkam','marine');

1 row created.

SQL> insert into stud values ('pruthvik',103,20,'anna nagar','aerospace');


1 row created.
SQL> insert into stud values ('charith',104,20,'kilpauk','mechanical');
1 row created.
SQL> select * from stud;

SNAME SID SAGE SAREASDEPT

Ashwin 101 19 Annanagar Aeronautical


Bhavesh 102 18 nungambakkam Marine
Pruthvik 103 20 Annanagar Aerospace
Charith 104 20 Kilpauk Mechanical
UPDATING THE TABLE:
SYNTAX:
UPDATEtable_name SETcolumn_name = value [, column_name = value
...][WHEREcondition]

SQL> alter table studs add ( spocket varchar2(20) );


Table altered.
SQL> update studs set spocket=750 where sid=101;
1 row updated.
7
211719104072

SQL> update studs set spocket=500 where sid=102;


1 row updated.
SQL> update studs set spocket=250 where sid=103;
1 row updated.
SQL> update studs set spocket=100 where sid=104;
1 row updated.
SQL> select * from studs;
SNAMESIDSAGE SAREASDEPT SPOCKET

Ashwin 101 19 Annanagar Aeronautical 750


Bhavesh 102 18 Nungambakkam Marine 500
Pruthvik 103 20 Annanagar Aerospace 250
Charith 104 20 Kilpauk Mechanical 100

RENAMING THE TABLE ‘STUD’:

SQL> rename stud to student;


Table renamed.

TCL COMMANDS
COMMIT:
SQL> commit;
The data is stored permanently.

SAVE POINT:

SQL>savepoint A;

SQL> insert into stud values('hari',105,20,'kilpauk','mechanical');


1 row created.
SQL> savepoint B;
Data updated till savepoint is stored and the data updated after that is not saved.
ROLLBACK:
SQL> rollback to A;
The data will Rollback to A.

8
211719104072

RESULT :
Thus the SQL commands for data definitions and data manipulation have been executed and the
output have been verified.

9
211719104072

EX .NO :2 DATABASE QUERYING- SIMPLE QUERIES AND NESTED QUERIES

DATE :26-02-2021

AIM:

To create table and execute simple and nested queries using SQL commands

DESCRIPTION:

ORDER BY CLAUSE - The order by clause arranges the contents of the table inascending
order (by default) or in descending order (if specified explicitly) according to the specified
column.

GROUP BY CLAUSE-The group by clause is another section of the select statement. This
optional class tells oracle to group rows based on distinct values that exists for specified
columns.

The having clause can be used in conjunction with the group by clause. Having imposes a
condition on the group by clause, which further filters the groups created by the group by
clause.

UNION CLAUSE: Multiple queries can be put together and their output combined using the
union clause. The union clause merges the output of two or more queries into a single set of
rows and columns.

INTERSECT CLAUSE: Multiple queries can be put together and their output can be
combined using the intersect clause. The intersect clause outputs only rows produced by both
the queries intersected. The output in an intersect clausewill include only those rows that are
retrieved by both the queries. SQL Correlated Subqueries
Correlated subqueries are used for row-by-row processing. Each subquery is executed once for
every row of the outer query.

JOINS:

Joins are normally used to retrieve data from more than one table

The keyword JOIN, joins one or more tables together in a results set.

To perform a join, there must be a common key that defines how the rows in the table
correspond to each other.

All sub-queries can be converted to joins, however ,all joins cannot be converted to sub-queries.

10
211719104072

COMMANDS

Subquery Syntax

SELECT select_list FROM table WHERE expr operator (SELECT select_list FROM
table);

– The subquery (inner query) executes once before the main query (outer query).

– The result of the subquery is used by the main query.

– In the syntax:

–operator includes a comparison condition such as >, =, or IN

– A subquery is a SELECT statement that is embedded in a clause of another


SELECTstatement. It can build powerful statements out of simple ones by using subqueries.
They can be very useful when user need to select rows from a table with a condition that
depends on the data in the table itself.

– Can place the subquery in a number of SQL clauses, including the following:

– WHERE clause
– HAVING clause

– FROM clause

USING THE WHERE CLAUSE

SQL> select sname,sage from studs where sage<=19;


SNAME SAGE

Ashwin 19
Bhavesh 18

BETWEEN OPERATOR

SQL> select sname,sarea, sid from studs where sid between 102 and 104;

SNAME SAREA SID

Bhavesh Nungambakkam 102


Pruthvik Anna Nagar 103
Charith kilpauk 104

11
211719104072

GROUP BY CLAUSE:

SQL> select sarea, sum(spocket) result from studs group by sarea;

SAREA RESULT

Annanagar 1000
Nungambakkam 500
Kilpauk 100

HAVING CLAUSE:

SQL> select sarea, sum(spocket) result from studs group by sarea having spocket<600;

SAREA RESULT

nungambakkam 500
kilpauk 100

CREATING TABLES FOR DOING SET OPERATIONS:

TO CREATE PRODUCT TABLE

SQL> create table product(prodname varchar2(30), prodno varchar2(10));

Table created.

SQL> insert into product values('table',10001);

1 row created.

SQL> insert into product values('chair',10010); 1 row created.

SQL> insert into product values('desk',10110);

1 row created.

SQL> insert into product values('cot',11110);

1 row created.

SQL> insert into product values('sofa',10010);

1 row created.

SQL> insert into product values('tvstand',11010);


1 row created.

12
211719104072

SQL> select * from product;

PRODNAME PRODNO

table 10001

chair 10010

desk 10110

cot 11110

sofa 10010

Tvstand 11010

TO CREATE SALE TABLE:

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


Table created.
SQL> insert into sale values('table',801,10001);
1 row created.
SQL> insert into sale values('chair',805,10010);
1 row created.
SQL> insert into sale values('desk',809,10110);
1 row created.
SQL> insert into sale values('cot',813,11110);

1 row created.

SQL> insert into sale values('sofa',817,10010);

1 row created.

SQL> select * from sale;

PRODNAME ORDERNO PRODNO

Table 801 10001

Chair 805 10010

Desk 809 10110

13
211719104072

Cot 813 11110

SET OPERATIONS:

SQL> select prodname from product where prodno=10010 union select prodname from sale where
prodno=10010;
PRODNAME

chair
sofa
SQL> select prodname from product where prodno=11110 intersect select prodname from sale
where prodno=11110;
PRODNAME

Cot

CORRELATED SUBQUERY
A correlated subquery is evaluated once for each row processed by the parent statement.
The parent statement can be a SELECT, UPDATE, or DELETE statement.

SQL>SELECT column1, column2, from table1 outerWHERE column1 operator


(SELECT column1, column2 from table2WHERE expr1 =outer.expr2);

A correlated subquery is one way of reading every row in a table and comparing values in
each row against related data. It is used whenever a subquery must return a different result
or set of results for each candidate row considered by the main query. In other words, user
can use a correlated subquery to answer a multipart question whose answer depends on the
value in each row processed by the parent statement.

CORRELATED UPDATE :

SQL> UPDATE table1 alias1SET column = (SELECT expression From table2 alias2WHERE
alias1.column =alias2.column);

Use a correlated subquery to update rows in one table based on rows from another table.

14
211719104072

JOINS:
CARTESIAN JOIN:
A Cartesian join is also known as cross join.
If there are two tables, then the Cartesian join is obtained when every row of one table is
joined to a row in another table.
SYNTAX

SQL>SELECT * FROM A,B;

EXAMPLE:
SQL>SELECT * FROM EMP,DEPT;

INNER JOIN:
The inner join joins two or more tables, returning only matched rows;
It require that both tables involved in join must have a primary- foreignkey relationship.

Example for an employee and department table ‘a’ is the alias for employee

‘b’ is the alias for department

SELECT a.emp_id,a.ename,b.loc_id,b.location FROM

employee a, department b WHERE a. id=b.emp_id;

Here ‘a’ is the alias name for Here ‘b’ is the alias name for
emp_id,enam
location

15
211719104072

OUTER JOIN:
The SQL OUTER JOIN command is used to display the elements in a table,regardless of
whether they are present in the second table.

THE OUTER JOIN:


Returns not only the common row from the tables ,but also returns the row that are unique
with in the tables.
Returns rows even if the rows from one table are not matching with those of another table.

OUTER JOIN TYPES:


ANSI method-> LEFT OUTER JOIN,RIGHT OUTER JOIN,FULL OUTER
JOIN(available from oracle version 9 onwards)

ISO method->(+) by placing this symbol in where clause,on the other side of the table,for
which all the rows need to be included.(available in Oracle 8i).

LEFT OUTER JOIN:


In the left outer join ,all the records from the table on the left of the OUTER JOIN
statement are returned.

SYNTAX:
SELECT Column_list FROM Left_table LEFT [OUTER] JOIN Right_Table ON
Condition.

EXAMPLES FOR LEFT OUTER JOIN:


SELECT nameJob,Sal,Dname from DEPT D Left join EMP E ON D.Deptno=E.Deptno;
Select e.ename,e.job,d.dname from deptd,emp e where d.deptno=e.deptno(+);

To display the Ename,job,andDname in which the employees are working along


with the DNAME in which no employees are working.

RIGHT OUTER JOIN:


In a right outer join, all the records from the table on the right of the OUTER JOIN are
returned.

16
211719104072

SYNTAX:

SELECT Column_List FROM Left_Table RIGHT [OUTER] JOIN Right table ON


condition

SYNTAX:

SELECT Column list FROM table t1,table t2 where t1.column_name(+) = t2.column_name

FULL OUTER JOIN:

A full outer join is essentially a combination of left and right outer joins, i.e.

The records from the table on left are included even if there are no matching records on the
right.
The records from the table on the right are included even if there are no matching record on the left.
SYNTAX:
SELECT Column_list FROM left_table FULL [OUTER] JOIN right _table ON condition.

EXAMPLES FOR FULL OUTER JOIN:


SELECT Ename, Job, Sal, Dname from Emp e Full join Dept d ON E.Deptno=D.Deptno;

Select e.ename,e.job,d.dname from deptd,emp e where d.deptno=e.deptno(+) union Select


e.ename,e.job,d.dname from deptd,emp e where d.deptno(+) =e.deptno

RESULT:
Thus, the SQL commands for database querying using simple and nested queries have been
executed successfully and the output is verified.

17
211719104072

EX.NO:3 VIEW,SEQUENCE,SYNONYMS AND SUB-QUERIES

EX.NO:3a) VIEWS

DATE: 05-03-2021

AIM:

To implement views using SQL commands

Syntax
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE [condition];

1.Query to create a view to have customer name and age from the CUSTOMERS table.

SQL> select * from customers;

SQL >create view customers_view as


select name, age
from customers;

View created.

SQL >select * from customers_view;

Updating a View

1.Query to update the age of Ramesh.

18
211719104072

SQL >update customers_view

set age = 35
where name = 'Ramesh';

Output:

Deleting Rows into a View


1.Query to delete a record having age = 22.

SQL >delete from customers_view


where age = 22;

OUTPUT:

INSERTING ROWS INTO A VIEW:

1. Query to insert a row into a view

SQL >insert into customers_view values('Anish',10);

Dropping Views
1.Query to drop the CUSTOMERS_VIEW from the CUSTOMERS table.

SQL >drop view customers_view;


View dropped.

SQL >select * from customers_view;

19
211719104072

OUTPUT:

ORA-00942: table or view does not exist

RESULT:

Thus the SQL commands to execute views have been executed successfully and the output is
verified.

20
211719104072

EX.NO:3b) SEQUENCES

DATE: 05-03-2021

AIM:

To implement sequences using SQL commands.

SYNTAX:

CREATE SEQUENCE sequence_name


START WITH initial_value
INCREMENT BY increment_value
MINVALUE minimum value
MAXVALUE maximum value
CYCLE|NOCYCLE ;

1. Query to create sequence in ascending order.

SQL>
create sequence sequence_1
start with 1
increment by 1
minvalue 0
maxvalue 100
cycle;

Sequence created.

SQL>create table students(id number(10),name char(20));

Table created.

SQL>insert into students values(sequence_1.nextval,'Ramesh');

1 row(s) inserted.

SQL>insert into students values(sequence_1.nextval,'Suresh');

1 row(s) inserted.

OUPUT:

SQL>select * from students;

I
NAME
D
1 Ramesh
2 Suresh

21
211719104072

Dropping Sequences

SQL>drop sequence students;

Sequence dropped.

2. Query to create sequence in descending order.

SQL>
create sequence sequence_2
start with 100
increment by -1
minvalue 1
maxvalue 100
cycle;

Sequence created.

SQL>create table students(id number(10),name char(20));

Table created.

SQL>insert into students values(sequence_2.nextval,'Ramesh');

1 row(s) inserted.

SQL>insert into students values(sequence_2.nextval,'Suresh');

1 row(s) inserted.

OUTPUT:

SQL>select * from students;

ID NAME
100 Ramesh
99 Suresh

DROPPING SEQUENCES:

SQL>drop sequence students;

Sequence dropped.

RESULT:

Thus the SQL commands to execute sequences have been executed successfully and the output
is verified

22
211719104072

EX.NO:3c) SYNONYMS

DATE: 05-03-2021

AIM:

To implement synonyms using SQL commands.

SYNTAX FOR CREATE SYNONYM:

CREATE SYNONYM synonym_name FOR object_name ;

1. Query to create a synonym for customers table

SQL>create table students(id number(10),name char(20));

Table created.

SQL>insert into students values(1,'Ramesh');

1 row(s) inserted.

SQL>insert into students values(2,'Suresh');

1 row(s) inserted.

SQL>create synonym s for students;

Synonym created.

SQL>select * from s;

I
NAME
D
1 Ramesh
2 Suresh

2. Query to drop a synonym

SQL>drop synonym s;
Synonym dropped.

RESULT:
Thus the SQL commands to execute synonyms have been executed successfully and the output
is verified
23
211719104072

EX.NO:4 DATABASE PROGRAMMING


EX.NO:4a) IMPLICIT CURSOR
DATE:12-03-2021

AIM:
To implement data programming using implicit cursors using SQL commands.

Write a PL/ SQL code using implicit cursors.

SQL> create table customers(id number, name varchar2(10), age number, address
varchar2(30),salary number);

Table created.

SQL>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 |

SQL>

Declare

total_rows number(2);

begin

update customers

set salary = salary + 500;

ifsql%notfound then

dbms_output.put_line('no customers selected');

elsifsql%found then

total_rows := sql%rowcount;

dbms_output.put_line(total_rows || ' customers selected ');

end if;

end;

24
211719104072

OUTPUT:

6 customers selected
1 row(s) updated.

SQL>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 |
----- ----------- ------ ----------------------- -------------

RESULT:

Thus the SQL program to execute data programming using implicit cursors have been executed
successfully and the output is verified.

25
211719104072

EX.NO:4b) EXPLICIT CURSORS

DATE: 12-03-2021

AIM: To implement data programming using explicit cursors using SQL commands.

SYNTAX:

cursorcursor_name is select * from table name;


To open the cursor:
opencursor_name;
To close the cursor:
closecursor_name;

Write PL/ SQL code using Explicit cursor.

SQL>create table customers(id number, name varchar2(10), age number,address


varchar2(30),salary number);

Table created.

SQL>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 |
----- ------------ ----- ------------ --------------------

SQL>

declare

c_idcustomers.id%type;

c_namecustomers.name%type;

c_addrcustomers.address%type;

cursorc_customers is

select id, name, address from customers;

begin

26
211719104072

openc_customers;

loop

fetchc_customers into c_id, c_name, c_addr;

exit when c_customers%notfound;

dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);

end loop;

closec_customers;

end;

OUTPUT:

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

RESULT:

Thus, the SQL program to execute data programming using explicit cursors have been executed
successfully and the output is verified.

27
211719104072

EX.NO:5 PROCEDURES AND FUNCTIONS

EX.NO:5a) PROCEDURES

DATE:19-03-2021

AIM:
To implement procedures using SQL programming.

SYNTAX:

create [or replace] procedure procedure_name


[(parameter_name [in | out | in out] type [, ...])]
{is | as}
begin
< procedure_body >
end procedure_name;

(i) Write a PL/SQL Procedure that displays the string 'Hello World!'

SQL>
create or replace procedure greetings
as
begin
dbms_output.put_line('Hello World!');
end;
/

begin
greetings;
end;
/

OUTPUT:

Hello World
Statement processed.

(ii) Write a PL/SQL Procedure that finds the minimum of two values.

SQL>

declare

a number;

b number;

28
211719104072

c number;

procedure findmin(x in number, y in number, z out number) is

begin

if x < y then

z:= x;

else

z:= y;

end if;

end;

begin

a:= 23;

b:= 45;

findmin(a, b, c);

dbms_output.put_line(' Minimum of (23, 45) : ' || c);

end;

Output:

Minimum of (23, 45) : 23


Statement processed.

(iii) Write a PL/SQL Procedure that computes the square of value of a passed value.

SQL>

Declare

a number;

procedure squarenum(x in out number) is

begin

x := x * x;

29
211719104072

end;

begin

a:= 23;

squarenum(a);

dbms_output.put_line(' Square of (23): ' || a);

end;

Output:

Square of (23): 529


Statement process

(iv) Write a PL/SQL Procedure code to insert record in user table.

SQL>create table user1(id number(10) primary key,name varchar2(100));

Table created

SQL>
create or replace procedure "insertuser" (id in number, name in varchar2)
is
begin
insert into user1 values(id,name);
end;
/

Procedure created.

SQL>
begin
insertuser(101,'Rahul');
dbms_output.put_line('Record inserted successfully');
end;
/
Record inserted successfully
Statement processed.

OUTPUT:

SQL> select * from user1;

ID Name
101 Rahul

30
211719104072

RESULT:

Thus,the SQL programs to execute procedures have been executed and the output is verified.

31
211719104072

EX.NO:5b) FUNCTIONS

DATE: 19-03-2021

AIM:

To implement functions using SQL program.

SYNTAX:

CREATE [OR REPLACE] FUNCTION function_name


[(parameter_name [IN | OUT | IN OUT] type [, ...])]
RETURN return_datatype
{IS | AS}
BEGIN
< function_body >
END [function_name];

(i) Write a PL/SQL function that computes and returns the addition of two numbers.

SQL>
create or replace function adder(n1 in number, n2 in number)
return number
is
n3 number(8);
begin
n3 :=n1+n2;
return n3;
end;
/

Function created

declare
n3 number(2);
begin
n3 := adder(11,22);
dbms_output.put_line('Addition is: ' || n3);
end;
/

OUTPUT:

Addition is: 33
Statement processed.

(ii) Write a PL/SQL function that computes and returns the maximum of two values.

32
211719104072

SQL>

declare

a number;
b number;
c number;
function findmax(x in number, y in number)
return number
is
z number;
begin
if x > y then
z:= x;
else
z:= y;
end if;
return z;
end;
begin
a:= 23;
b:= 45;
c := findmax(a, b);
dbms_output.put_line(' Maximum of (23,45): ' || c);
end;
/
OUTPUT:

Maximum of (23,45): 45
Statement processed.
(iii) Write a PL/SQL function that will return the total number of CUSTOMERS in the
customers table.

SQL> create table customers(id number, name varchar2(10), age number, address varchar2(30),
salary number);

Table created.

33
211719104072

SQL>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 |
-

SQL>
create or replace function totalcustomers
return number is
total number(2) := 0;
begin
select count(*) into total from customers;
return total;
end;
/

Function created.

declare
c number(2);
begin
c := totalcustomers();
dbms_output.put_line('Total no. of Customers: ' || c);
end;
/

OUTPUT:

Total no. of Customers: 6


Statement processed.
(iv) Write a PL/SQL function that calculates the factorial of a number.

SQL>

declare
num number;
factorial number;
function fact(x number)
return number
is

34
211719104072

f number;
begin
if x=0 then
f := 1;
else
f := x * fact(x-1);
end if;
return f;
end;
begin
num:= 6;
factorial := fact(num);
dbms_output.put_line(' Factorial '|| num || ' is ' || factorial);
end;
/

OUTPUT:

Factorial 6 is 720
Statement processed.

RESULT:

Thus,the SQL programs to execute functions have been executed and the output is verified.

35
211719104072

EX.NO:6 TRIGGERS

DATE: 20-03-2021

AIM:

To implement Triggers using SQL program.

SYNTAX FOR CREATING TRIGGER:

create [or replace ] trigger trigger_name


{before | after | instead of }
{insert [or] | update [or] | delete}
[of col_name]
on table_name
[referencing old as o new as n]
[for each row]
when (condition)
declare
declaration-statements
begin
executable-statements
exception
exception-handling-statements
end;
i) Create a row level trigger for the customers table that would fire for INSERT or UPDATE
or DELETE operations performed on the CUSTOMERS table. This trigger must display the
salary difference between the old values and new values

SQL>create table customers(id number, name varchar2(10), age number, address


varchar2(30),salary number);

Table created.

SQL> 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 |

36
211719104072

| 5 | Hardik | 27 | Bhopal | 8500.00 |


| 6 | Komal | 22 | MP | 4500.00 |

SQL>

create or replace trigger display_salary_changes


before delete or insert or update on customers
for each row
when (new.id > 0)
declare
sal_diff number;
begin
sal_diff := :new.salary - :old.salary;
dbms_output.put_line('old salary: ' || :old.salary);
dbms_output.put_line('new salary: ' || :new.salary);
dbms_output.put_line('salary difference: ' || sal_diff);
end;
/

Trigger created.

DML operations on the CUSTOMERS table:

SQL>insert into customersvalues (7, 'kriti', 22, 'HP', 7500.00 );


1 row(s) inserted.

SQL> select * from customers;

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

| ID | NAME | AGE | ADDRESS | SALARY |

| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |


| 2 | Khilan | 25 | Delhi | 2000.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 |
| 7 | Kriti | 22 | HP | 7500.00 |

OUTPUT:

old salary: 7500


new salary: 7500
salary difference: 0

SQL>update customers
set salary = salary + 500
where id = 2;

37
211719104072

OUTPUT:

Old salary: 1500


New salary: 2000
Salary difference: 500

SQL> select * from customers;

| ID | NAME | AGE | ADDRESS | SALARY |

| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |


| 2 | Khilan | 25 | Delhi | 2000.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 |

RESULT:

Thus,the SQL programs to execute triggers have been executed successfully and the output is
verified.

38
211719104072

EX .NO: 7 EXCEPTION HANDLING

DATE :26-03-2021

AIM:

To implement exception handling using SQL programs.

THEORY:

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


PL/SQLsupports programmers to catch such conditions using EXCEPTION block in the
program and anappropriate action is taken against the error condition. There are two types
of exceptions:
System-defined exceptions

User-defined exceptions

SYNTAX FOR EXCEPTION HANDLING:

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

39
211719104072

exception3-handling-statements

END;
Example

DECLARE
pssn number(4);
pfname varchar2(15);
pbdate date;
BEGIN
SELECT fname, bdate INTO pfname, pbdate
FROM employee205
WHERE ssn = &pssn;
DBMS_OUTPUT.PUT_LINE ('Name: '|| pfname);
DBMS_OUTPUT.PUT_LINE ('Date of Birth: ' || pbdate);
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No such Employee!');
WHEN others THEN
dbms_output.put_line('Error!');
END;

EXECUTION 1:
Enter value for pssn: 999
old 8: WHERE ssn = &pssn;
new 8: WHERE ssn = 999;
Name: NANDA
Date of Birth: 30-MAY-05

PL/SQL procedure successfully completed.

40
211719104072

EXECUTION 2:

Enter value for pssn: 100


old 8: WHERE ssn = &pssn;
new 8: WHERE ssn = 100;
No such Employee!
PL/SQL procedure successfully completed.

Raising Exceptions

Exceptions are raised by the database server automatically whenever there is any internal
database

error, but exceptions can be raised explicitly by the programmer by using the command
RAISE.

Following is the simple syntax of raising an exception:

DECLARE
exception_name EXCEPTION;
BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name THEN
statement;
END;

USER-DEFINED EXCEPTIONS:
PL/SQL allows to define own exceptions according to the need of the program. A user-
defined exception must be declared and then raised explicitly, using either a RAISE
statement or the procedure

DBMS_STANDARD.RAISE_APPLICATION_ERROR.

The syntax for declaring an exception is:

41
211719104072

DECLARE

my-exception EXCEPTION;

Example:

The following example illustrates the concept. This program asks for assn, when the user
enters an invalid ssn, the exception invalid_ssn is raised.

DECLARE
pssn number(4);
inputssn number(4);
pfname varchar2(15);
pbdate date;
invalid_ssn EXCEPTION;
BEGIN
PSSN:=&inputssn;
IF Pssn<= 0 THEN
RAISE invalid_ssn;
ELSE
SELECT fname, bdate INTO pfname, pbdate
FROM employee205
WHERE ssn = pssn;
DBMS_OUTPUT.PUT_LINE ('Name: '|| pfname);
DBMS_OUTPUT.PUT_LINE ('Date of Birth: ' || pbdate);
END IF;
EXCEPTION
WHEN invalid_ssn THEN
dbms_output.put_line('SSN must be greater than zero!');
WHEN no_data_found THEN
dbms_output.put_line('No such Employee!');
WHEN others THEN
dbms_output.put_line('Error!');
END;
/
SQL> /

42
211719104072

Enter value for inputssn: 999


old 8: PSSN:=&inputssn;
new 8: PSSN:=999;
Name: NANDA
Date of Birth: 30-MAY-05

PL/SQL procedure successfully completed.

SQL> /
Enter value for inputssn: 200

old 8: PSSN:=&inputssn;
new 8: PSSN:=200;
No such Employee!

PL/SQL procedure successfully completed.

SQL> /
Enter value for inputssn: 0
old 8: PSSN:=&inputssn;
new 8: PSSN:=0;
SSN must be greater than zero!
PL/SQL procedure successfully completed.

RESULT:

Thus,the SQL programs to execute triggers have been executed successfully and the output is
verified.

43
211719104072

EX.NO:8 DATABASE DESIGN USING ER MODELLING NORMALIZATION AND

APPLICATION
DATE: 09-04-2021

AIM:

To implement database design using ER modeling normalization and application in SQL.

ER DIAGRAM:

CHEN NOTATION:

ORDER (OrderNum(key), OrderDate, SalesPerson)


ORDERITEMS (OrderNum(key)(fk) ,ItemNum(key), PartNum, Quantity, Cost)

In the above example, in the ORDERITEMS Relation: OrderNum is the Foreign

Key and OrderNum plus ItemNum is the Composite Key.

CHEN NOTATION:

44
211719104072

REPRESENTING RELATIONSHIPS:

1:1 Relationships. The key of one relation is stored in the second


relation.Look at example queries to determine which key is queried most
often.

1: N Relationships.

Parent - Relation on the "1" side.


Child - Relation on the "Many" side.

Represent each Entity as a relation.


Copy the key of the parent into the child relation.

CUSTOMER (CustomerID (key), Name, Address, ...)


ORDER (OrderNum (key), OrderDate, SalesPerson, CustomerID (fk))
M:N Relationships. Many to Many relationships can not be directly implemented inrelations.

Solution: Introduce a third Intersection relation and copy keys from original two
relations.

CHEN NOTATION:

SUPPLIER (SupplierID (key), FirmName, Address, ...)

COMPONENT (CompID (key), Description, ...)


SUPPLIER_COMPONENT (SupplierID (key), CompID (key))

Note that this can also be shown in the ER diagram. Also, look for potential added
attributes in the intersection relation.

45
211719104072

DATABASE DESIGN USING ER MODELING, NORMALIZATION AND


IMPLEMENTATION FOR SALES ORDER

FIRST NORMAL FORM EXAMPLE:


The new table is as follows:

SalesOrderNo, ItemNo, Description, Qty, UnitPrice

The repeating fields will be removed from the original data table, leaving the following.

SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo, ClerkName

These two tables are a database in first normal form

SECOND NORMAL FORM EXAMPLE:


The new table will contain the following fields:

ItemNo, Description

All of these fields except the primary key will be removed from the original table. The primary key
will be left in the original table to allow linking of data:

SalesOrderNo, ItemNo, Qty, UnitPrice

46
211719104072

Never treat price as dependent on item. Price may be different for different sales orders (discounts,
special customers, etc.)

Along with the unchanged table below, these tables make up a database in second normal form:

SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo, ClerkName

THIRD NORMAL FORM EXAMPLE:


The new tables would be:

CustomerNo, CustomerName, CustomerAdd

ClerkNo, ClerkName

All of these fields except the primary key will be removed from the original table. The primary key
will be left in the original table to allow linking of data as follows:

SalesOrderNo, Date, CustomerNo, ClerkNo

Together with the unchanged tables below, these tables make up the database in third normal form.

ItemNo, Description

SalesOrderNo, ItemNo, Qty, UnitPrice

COMPLETED TABLES IN THIRD NORMAL FORM:


Customers: CustomerNo, CustomerName, CustomerAdd

Clerks: ClerkNo, ClerkName

Inventory Items: ItemNo, Description

Sales Orders: SalesOrderNo, Date, CustomerNo, ClerkNo

SalesOrderDetail: SalesOrderNo, ItemNo, Qty, UnitPrice

47
211719104072

ER DIAGRAM FOR THE SALES ORDER AFTER NORMALIZATION:

RESULT:

Thus,the SQL programs to execute data design using ER modeling normalization and application
have been executed successfully and the output is verified.

48
211719104072

EX.NO: 9 DATABASE CONNECTIVITY WITH FRONT END


TOOLS
DATE :16-04-2021

AIM:

To implement database connectivity with front end tools using SQL

PHASES OF PROJECT DEVELOPMENT:

1. Requirement Analysis(collect client requirements and analyze it.)

2. Design phase(prepare design according to the requirements)

2.1 DATABASE DESIGN:

A good database design is, therefore, one that:

Divides information into subject-based tables to reduce redundant data.

Provides Access with the information it requires to join the information in the tables
together as needed.

Helps support and ensure the accuracy and integrity of information.

Accommodates data processing and reporting needs.

2.1.1 THE DESIGN PROCESS:

The design process consists of the following steps:

Determine the purpose of database: This helps to prepare for the remaining steps.

2.1.2 Find and organize the information required: Gather all of the types of information to
record in the database, such as product name and order number.

2.1.3 Divide the information into tables: Divide information items into major entities
orsubjects, such as Products or Orders. Each subject then becomes a table.

49
211719104072

2.1.4 Turn information items into columns: Decide what information to store in eachtable. Each
item becomes a field, and is displayed as a column in the table. For example, an Employees
table might include fields such as Last Name and Hire Date.

2.1.5 Specify primary keys: Choose each table’s primary key. The primary key is a column thatis
used to uniquely identify each row. An example might be Product ID or Order ID.

2.1.6 Set up the table relationships: Look at each table and decide how the data in one table
isrelated to the data in other tables. Add fields to tables or create new tables to clarify the
relationships, as necessary.

2.1.7 Refine the design: Analyze the design for errors. Create the tables and add a few recordsof
sample data. See if it can get the results from the tables. Make adjustments to the design, as
needed.

2.1.8. Apply the Normalization rules:

2.1.9. Draw Entity Relationship Diagram:

2.2 User Interface Design

These are ten general principles for user interface design. They are called "heuristics"
because they are more in the nature of rules of thumb than specific usability guidelines.by
Jakob Nielsen

2.2.1 Visibility of system status

The system should always keep users informed about what is going on, through
appropriate feedback within reasonable time.

2.2.2 Match between system and the real world

The system should speak the users' language, with words, phrases and concepts familiar to
the user, rather than system-oriented terms. Follow real-world conventions, making
information appear in a natural and logical order.

50
211719104072

2.2.3 User control and freedom

Users often choose system functions by mistake and will need a clearly marked "emergency
exit" to leave the unwanted state without having to go through an extended dialogue.
Support undo and redo.

2.2.4 Consistency and standards

Users should not have to wonder whether different words, situations, or actions mean the
same thing. Follow platform conventions.

2.2.5 Error prevention

Even better than good error messages is a careful design which prevents a problem from
occurring in the first place. Either eliminate error-prone conditions or check for them and
present users with a confirmation option before they commit to the action.

2.2.6 Recognition rather than recall

Minimize the user's memory load by making objects, actions, and options visible. The user
should not have to remember information from one part of the dialogue to another.
Instructions for use of the system should be visible or easily retrievable whenever
appropriate.

2.2.7 Flexibility and efficiency of use

Accelerators -- unseen by the novice user -- may often speed up the interaction for the
expert user such that the system can cater to both inexperienced and experienced users.
Allow users to tailor frequent actions.

2.2.8 Aesthetic and minimalist design

Dialogues should not contain information which is irrelevant or rarely needed. Every extra
unit of information in a dialogue competes with the relevant units of information and
diminishes their relative visibility.

2.2.9 Help users recognize, diagnose, and recover from errors:

Error messages should be expressed in plain language (no codes), precisely indicate the
problem, and constructively suggest a solution.

2.2.10 Help and documentation

51
211719104072

Even though it is better if the system can be used without documentation, it may be
necessary to provide help and documentation. Any such information should be easy to
search, focused on the user's task, list concrete steps to be carried out, and not be too large.

Front End Tool

Visual Basic 6.0 is a robust, object-oriented, sophisticated and powerful development


platform,ideally suited for producing impressive Windows applications.

The major advantages of VB are:

It is a powerful and complete Windows application development system that enables us


to use built-in functions and subroutines for dozens of different tasks.

It also provides capability to produce custom libraries and objects that can be loaded at
runtime or bound into the distributed application.

It is a hugely successful product preferred by millions of developers at virtually all skill


levels.
It is well supported by third party products

It supports the principle of object driven design


It is very flexible and user-friendly as it is a GUI (Graphic User Interface)

Every time the user load a VB or VBA project, user will be greeted by roughly the layout
shown in Figure and these five GUI tools. First, the toolbox(1) contains all the GUI
elements/controls needed to create any VB form and the front end to all VB programs. For
example, after the pointer tool there is the image control, label, textbox, and frame and command

52
211719104072

button as the first five of 20 standard controls which are used constantly in VB programs. Another
advantage of these basic controls is that they fill 60-90% of all programming needs and are
automatically included in the VB runtime.

Second is form(2). Think of it as it can size it, color it, give it a caption("Database Test" in
this case) and fill the form with GUI controls which helps the program do useful works. Putting
controls on the form is as easy as clicking on the control (say the command button) in the toolbox
and then dragging and sizing it on the form (see the "Exit" button on the form).

The third part of the Basic canvas is the menus and toolbars (3) which manage and control
all of VB/VBA.Most of us will be familiar with many of the menu and icons. File, Edit, View, Run,
Window, Help menus should be familiar to any Word Perfect, Excel, or Netscape users. Likewise
icons for File Open, File Save, Cut, Copy, Paste, Find, Run programs, Pause Program, Halt
Program can be seen along the toolbar. Along with built in wizards and custom command centers in
some controls, this is the heart of VB.

Fourth is the Project Explorer (4) which user uses to access all the forms and coding
filesin the VB program. The PE-Project Explorer is such a handy navigation device which will find
using it all the time to switch among different forms and code.

Fifth and even more frequently used than the Project Explorer is the Properties sheet (5).
Note that the "Exit" command button is highlighted in the form and is also the control listed in the
Properties sheet. The Properties sheet is both the elegance and the swamp of VB. If user want to
change the property of any control like its color, shape, caption, or whatever - the Property sheet is
the place to go. But a command button has 32 properties - and some controls have hundreds, hence
the swamp.

User will find in developing in Visual Basic that spends a large percentage of time using the
Project Explorer and Property sheet. It is worthwhile to get to know them well. Project Explorer
is the means of navigating around the various parts of VB; while Property sheets allows to set the
very basic look and feel plus behavior of all the forms in Visual Basic.

53
211719104072

Summary of Major Visual Basic Canvas Features

The toolbox icon - toggles the main toolbox of form controls on and off.

The form icon in the Project Explorer. Click on this and the active Form
will appear in the edit window.
The toolbar handle. Every toolbar has one. Pull on it to move/reposition
the toolbar anywhere on the screen.

The Project Explorer icon - toggle this to make the Project Explorer appear
or disappear.

Property sheet icon - toggle this to make the Property sheet appear or
disappear.

FORM DESIGN:

Develop proper forms:

Forms don’t usually get much attention from code-level developers. We add a form and off we
go, plugging in various controls and using them as containers for information. But setting up
forms’ properties is important for creating visually pleasant, consistent, and intuitive interfaces.

It should specify the proper border style of a form. The options are:

None

Fixed Single

Sizable

Fixed Dialog

Fixed ToolWindow

Sizable ToolWindow

Using None is rarely a good idea, since such forms don’t have a title bar or the control menu
box,so users can’t close or resize them. The default form value is Sizable (allowing users to
resize theform), but this is a good choice only in cases where all the form elements are designed
to resizealong with the form itself.The Fixed Dialog style offers a border and doesn’t allow a
form to beresized, but it lacks Minimize and Maximize buttons in the top-right corner. To
include thosebuttons, use the Fixed Single style. Sizable ToolWindow and Fixed
54
211719104072

ToolWindow styles aregenerally used for forms that need to float over and allow changes to be
made to the main forms.

User should also address the form’s start position. The available start position styles are:

Manual

Windows Default

CenterScreen

CenterOwner

The default style is Manual, which means that the form will appear in the same location at both
runtime and design time. Windows Default puts a form in the upper-left corner on the screen.
CenterScreen places a form in the center of the user’s screen regardless of the screen resolution.
CenterOwner places a form in the center of the owner form. An owner is a form on top of which
the current form is to appear. When no owner is specified, the form shows up in the center of
the desktop.

Keep controls consistent and appropriate

Before simply dropping controls on a form, consider what kind of data the control will oversee
and how the users will interact with that data. The guidelines provided below will help user
choose the best controls for a particular type of data.

The first rule of form controls is that they should have consistent characteristics, such as look,
feel, and size. Users shouldn't need to learn specific visual cues and usage parameters for each
control.

The text box controls should be the same height as the combo boxes. By default, the height
property of text boxes is different from that of the combo boxes. User should change the height
value of the text boxes to match that of the combo boxes (since the height property is read-only
in combo boxes). Obviously, this rule applies only to single-line text boxes.

User should use the proper controls for the data need to display. If user is displaying read-only
data, you should not use a text box and modify its properties so that other users can’t make
changes to its text. Instead, use a label. Text box controls should be used only for editable data.

55
211719104072

When there is a need to display fewer than five options in a list and the user has to choose only
one item, option buttons are the best choice. Many applications use combo boxes to display
such information, but from the user's standpoint, it’s much better to see all options at once
rather than having to scroll through the listings in a combo box.

Keep in mind that when users should be able to select more than one item from a small list of
selections, using check boxes is a good idea. As with option buttons, check boxes let users see
all options available at the same time, but check boxes also allow the selection of multiple items
from the list.

When need to display a larger number of items for users to choose from, it’s not feasible to use
option buttons or check boxes because of the amount of real estate they would take up on the
form. In such cases, display data either in combo boxes or list boxes to save space.use multiple-
selection list boxes to let users select more than one item at a time; combo boxes allow only one
item to be selected.

Developers sometimes use combo boxes and list boxes to display more than one column of
data; however, grid controls may be easier for users to understand (and easier to code).

When using labels next to corresponding controls, left-align the labels and follow label captions
with a colon for better readability. Also, align labels vertically to the corresponding controls.
Figure A provides an example of these label rules in action.

FIGURE A

Always set the BackStyle property of label controls to Transparent to make sure that labels have
the same BackColor as the parent form.

56
211719104072

Whenever there is a need to prevent users from using a control temporarily, it’s preferable to
disable the control rather than hide it. Disabling a control prevents the user from clicking it, but
it doesn’t significantly alter the way the form looks. Hiding controls may take the users by
surprise or lead them to believe that something is wrong with an application. When selecting
controls, also consider newer VB options, such as Tab Control, Tree View, Progress Bar, and
Toolbar, to improve the form layout and design.

SAMPLE FORM DESIGNS:

Login Form User Interface Design View

Login Form after Execution

57
211719104072

Sample User Interface Design To Display Book Details

Note : Necessary Fields can be added as per Requirement

MENU DESIGN:

THEORY:

Adding Menu Bar Using Menu Editor

To start adding menu items to the application, open an existing project or start a new
project, then click on Tools in the menu bar of the Visual Basic IDE and select Menu
Editor. click on the Menu Editor, the Menu Editor dialog will appear. In the Menu Editor
dialog , key in the first item File in the caption text box. use the ampersand ( & ) sign in
front of F so that F will be underlined when it appears in the menu, and F will become the
hot key to initiate the action under this item by pressing the Alt key and the letter F. After
typing &File in the Caption text box, move to the name textbox to enter the name for this
menu item, type in menuFile here. Now, click the Next button and the menu item &File will
move into the empty space below, as shown in the following diagram:

58
211719104072

Then add in other menu items on the menu bar by following the same procedure, as shown
in the diagram below:

59
211719104072

Click Ok, the menu items will be shown on the menu bar of the form.

Now, proceed to add the sub menus. In the Menu Editor, click on the Insert button between
File and Exit and then click the right arrow key, and the dotted line will appear. This shows
the second level of the menu, or the submenu. Now key in the caption and the name. Repeat
the same procedure to add other submenu items. Here, we are adding New, Open, Save,
Save As and Exit.

60
211719104060

Now click the OK button and go back to the form. To see the dropped down
submenus click on the item File, as shown.

Finally, enter the code by clicking on any of the submenu items.

PRACTICE EXERCISE:

Add Menu as per Specification and sample


given. In the intro form add following
Menus Personal

Personal
Detail
Branch wise
Detail
Mark

Mark Detail
Grade Detail

Exit

61
211719104060

62
211719104060

63
211719104060

In the Personal Information form add Menu to navigate to the Main Menu(Intro Form)

In the Mark form add Menu to navigate to the Grade Details(Grade Form)

In the Grade form add Menu to navigate to the Mark Details(Mark Form)

64
211719104060

Add Exit and Back as Required.

CODING:

Sample Coding for Intro Form

Private Sub Exit_Click()


End
End Sub
Private Sub GradeDetail_Click()
Unload Me
Load Grade
Grade.Show
End Sub
Private Sub MarkDetail_Click()
Unload Me
Load Mark
Mark.Show
End Sub
Private Sub PersonalDetail_Click(Index As Integer)
Unload Me
Load Student
Student.Show
End Sub

65
211719104060

SAMPLE CODING FOR INTRO FORM:

Private Sub cmdmovenext_Click()


Adodc1.Recordset.MoveNext

If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End Sub
Private Sub cmdmoveprev_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
End If

End Sub

Private Sub cmdnew_Click()


Adodc1.Recordset.AddNew
End Sub

Private Sub cmdsave_Click()


Adodc1.Recordset.Update
End Sub

Private Sub Command1_Click()


cs = "select * from branch where branchname = '" &
Adodc2.Recordset("branchname") &

"'"MsgBoxcs
End Sub

Private Sub Mainmenu_Click()

66
211719104060

Unload Me
Load Intro

Intro.Show
End Sub

RESULT:

Thus,the data connectivity with front end tools has been executed successfully and the output
is verified.

67
211719104060

EX.NO:10 CASE STUDY USING REAL LIFE DATABASE APPLICATION

DATE:23-04-2021

AIM:

To implement case study using real life database application using SQL commands.

DETAILS OF THE STEP:

1. Create the DB for banking system source request the using SQL

2.Establishing ODBC connection

3.Click add button and select oracle in ORA home 90 click finished

4.A window will appear give the data source name as oracle and give the user id as scott

5. Now click the test connection a window will appear with server and user name give user
as scott and password tiger Click ok

6. ISUAL BASIC APPLICATION:-

>>Create standard exe project in to and design ms from in request format

>>To add ADODC project select component and check ms ADO data control click
ok.
>>Now the control is added in the tool book
>>Create standard exe project in to and design ms from in request format

ADODC CONTROL FOR ACCOUNT FROM:- Click customs and property window and
window will appear and select ODBC data source name as oracle and click apply as the
some window.

68
211719104060

CREATE A TABLE IN ORACLE


SQL>create table account(cname varchar(20),accno number(10),balance
number); Table Created

SQL> insert into account values('&cname',&accno,&balance);

Enter value for cname: Mathi

Enter value for accno: 1234

Enter value for balance: 10000

old 1: insert into account values('&cname',&accno,&balance)

new 1: insert into emp values('Mathi',1234,10000) 1 row created.

SOURCE CODE FOR FORM1

Private Sub ACCOUNT_Click()

Form2.Show

End Sub

Private Sub

EXIT_Click()

Unload Me

End Sub

Private Sub

69
211719104060

TRANSACTION_Click()

Form3.Show

End Sub

SOURCE CODE FOR FORM 2

Private Sub CLEAR_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

End Sub

Private Sub

DELETE_Click()

Adodc1.Recordset.DELETE MsgBox "record deleted"

Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF = True Then

Adodc1.Recordset.MovePrevious

End If

End Sub

Private Sub EXIT_Click()

70
211719104060

Unload Me

End Sub

Private Sub

HOME_Click()

Form1.Show

End Sub

Private Sub

INSERT_Click() Adodc1.Recordset.AddNew

End Sub

Private Sub

TRANSACTION_Click()

Form3.Show

End Sub

Private Sub UPDATE_Click() Adodc1.Recordset.UPDATE MsgBox "record updated

successfully"

End Sub

71
211719104060

SOURCE CODE FOR FORM 3

Private Sub ACCOUNT_Click()

Form2.Show

End Sub

Private Sub CLEAR_Click()

Text1.Text = ""

Text2.Text = ""

End Sub

Private Sub

DEPOSIT_Click()

Dim s As String s = InputBox("enter the amount to be deposited")

Text2.Text = Val(Text2.Text) + Val(s) A = Text2.Text MsgBox "CURRENT BALANCE


IS Rs" + Str(A) Adodc1.Recordset.Save Adodc1.Recordset.UPDATE

EndSub

PrivateSub

EXIT_Click()

UnloadMe

EndSub

72
211719104060

PrivateSub

HOME_Click()

Form1.Show End

Sub Private Sub

WITHDRAW_Click()

Dim s As String s = InputBox("enter the amount to be deleted")

Text2.Text = Val(Text2.Text) - Val(s) A = Text2.Text MsgBox "current balance is Rs" +

Str(A)

Adodc1.Recordset.Save

Adodc1.Recordset.UPDATE

End Sub

73
RESULT:

Thus,the case study using real life database application has been executed successfully and
the output is verified.

74
EX.NO: 11 DISTRIBUTED DATABASE

DATE:30-04-2021

AIM:

To implement distributed database using SQL

Description:
A distributed database is a database in which storage devices are not all attached to a
common processing unit such as the CPU, controlled by a distributed database management
system. (together sometimes called a distributed database system). It may be stored in multiple
computers, located in the same physical location; or may be dispersed over a network of
interconnected computers. Unlike parallel systems, in which the processors are tightly coupled
and constitute a single database system, a distributed database system consists of loosely-coupled
sites that share no physical components.
There are two principal approaches to store a relation r in a distributed database system:
A) Replication
B) Fragmentation/Partitioning

A) Replication: In replication, the system maintains several identical replicas of the same relation
r in different sites.

 Data is more available in this scheme.


 Parallelism is increased when read request is served.
 Increases overhead on update operations as each site containing the replica needed
to be updated in order to maintain consistency.
 Multi-datacenter replication provides geographical diversity:

B) Fragmentation: The relation r is fragmented into several relations r1, r2, r3......rn in such a way
that the actual relation could be reconstructed from the fragments and then the fragments are
scattered to different locations. There are basically two schemes of fragmentation:

 Horizontal fragmentation - splits the relation by assigning each tuple of r to one or


more fragments.
 Vertical fragmentation - splits the relation by decomposing the schema R of
relation r.

Implementing distributed databases using SQL Server 2005

Linked servers provide SQL Server the ability to access data from remote data sources. Using these
mechanisms, we can issue queries, perform data modifications and execute remote procedures.
We can use the T-SQL function OPENROWSET to query a remote data source without a linked
server.

75
Steps:

1. Create Horizontal Partition:


First partition a table horizontally. In designing a partitioning scheme, it must
be clear what data belongs to each member table. The original table is
replaced with several smaller member tables. Each member table has the
same number of columns as the original table, and each column has the same
attributes as the corresponding column in the original table, such as data type,
size, and collation. By using a distributed partitioned view, each member
table is on a separate member server. For the greatest location transparency,
the name of the member databases should be the same on each member
server, although this is not required.For
example: Server1.CustomerDB, Server2.CustomerDB, Server3.CustomerDB.
1.1 Creating Member Tables
Design the member tables so that each table stores a horizontal slice of the
original table based on a range of key values. The ranges are based on the
data values in a partitioning column. The range of values in each member
table is enforced by a CHECK constraint on the partitioning column, and
ranges cannot overlap.The CHECK constraint for this table is the following:
-- On Server1:
CREATE TABLE
Customers_33
(CustomerID
INTEGER
PRIMARY KEY
CHECK (CustomerID BETWEEN 1 AND 32999),
... -- Additional column definitions)

Similarly create a member table on the other server instances.

2. Create Linked Server:


The servers that can be referenced in queries are called linked servers. A
linked server is any data source that can be accessed using OLE DB
– It can be another SQL Server or
– A different database server (such as Oracle) or
– A simpler data source, such as a file (Excel, Access)

Create a linked server to another SQL Server instance using the T-SQL
procedure sp_addlinkedserver. The syntax of sp_addlinkedserver is

EXECsp_addlinkedserver

[@server= ] 'server'

, [ @provider= ] 'provider_name'

,[ @srvproduct= ] 'product_name' [
, [ @datasrc= ] 'data_source'
[ , [ @location= ] 'location' ]
[ , [ @provstr= ] 'provider_string'

76
[ , [ @catalog= ] 'catalog' ]

And each parameter is described as

Parameter Description
Server Local name used for the linked server.
Product name of the OLE DB data source. For SQL Server instances, the
product_name
product_name is 'SQL Server'.
This is the unique programmatic identifier for the OLE DB provider. When not
provider_name specified, the provider name is the SQL Server data source. The explicit
provider_name for SQL Server is SQLNCLI (for Microsoft SQL Native Client
OLE DB Provider).
data_source This is the data source as interpreted by the OLE DB provider.
Location The location interpreted by the OLE DB provider.
provider_string The connection string specific to the OLE DB provider.
Catalog This varies from the database systems.

3. Add linked server definitions on each member server that contains the
connection information required to run distributed queries on the other
member servers. This gives a distributed partitioned view access to
data on the other servers.
4. Defining Distributed Partition Views:
After you create the member tables, you define a distributed partitioned view on
each member server, with each view having the same name. This
enables queries that reference the distributed partitioned view name to
run on one or more of the member servers. The system operates as if a
copy of the original table is on each member server, but each server
has only a member table and a distributed partitioned view.
 Create the following distributed partitioned view:
CREATE VIEW Customers AS select statement

To execute queries on the remote instance, Distributed queries referring to


linked server name is written by using the following syntax
[linked_server_name].[catalog].[schema].[object_name]

Create a distributed partitioned view on other server instances also.

Queries:
1. Insert and

Display details in

each table. insert

77
into <tablename>

values(list of

values); select

*from

<tablename>;

SELECT * FROM OPENQUERY (Server1, 'SELECT * FROM


bookstore.dbo.Books_1')
2. Find the total number of books in stock where price is between $15 and $55.

select sum(totalstock) 'Total Books' from BooksView where price between 25 and
100
3. Update the book price of book No=1234 from $45 to $55 at site S3.

update openquery(Server2,'select price from bookstore.dbo.Books_1


where ISBN=45') set price=100
(1 row(s) affected)
4. Find total number of book at site S2.

select *from openquery(cs03c025,'select sum(totalstock) from


bookstore.dbo.Books')
Create three databases
names S1,S2,S3,S4.
Create the following
tables in all of them

USE [S1]

GO

/****** Object: Table [dbo].[Books] Script Date: 3/8/2014 4:10:30 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[Books](

78
[ISBN] [uniqueidentifier] NOT NULL,

[PrimaryAuthor] [varchar](50) NULL,

[Topic] [varchar](50) NULL,

[TotalStock] [int] NULL,

[Price] [decimal](18, 0) NULL,

CONSTRAINT [PK_Books] PRIMARY KEY CLUSTERED

[ISBN] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,


IGNORE_DUP_KEY

= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON


[PRIMARY]

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

GO

USE [S4]

GO

/****** Object: Table [dbo].[BookStore] Script Date: 3/8/2014 3:07:23 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[BookStore](

[StoreNo] [uniqueidentifier] NOT NULL,

[City] [varchar](50) NULL,

79
[State] [varchar](50) NULL,

[Zip] [varchar](50) NULL,

[InventoryValue] [decimal](18, 0) NULL,

CONSTRAINT [PK_BookStore] PRIMARY KEY CLUSTERED

[StoreNo] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,


IGNORE_DUP_KEY

= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON


[PRIMARY]

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

GO

USE [S4]

GO

drop table [Stock]

/****** Object: Table [dbo].[Stock] Script Date: 3/8/2014 3:07:50 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[Stock](

[StoreNo] [uniqueidentifier] NOT NULL,

[ISBN] [uniqueidentifier] NOT NULL,

80
[Qty] [int] NULL

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

GO

ALTER TABLE [dbo].[Stock] WITH CHECK ADD CONSTRAINT


[FK_Stock_BookStore]

FOREIGN KEY([StoreNo])

REFERENCES [dbo].[BookStore] ([StoreNo])

GO

ALTER TABLE [dbo].[Stock] CHECK CONSTRAINT [FK_Stock_BookStore]

GO

--Insert and Display details in each table

insert into s1.dbo.Books values(newid(),&#39;Sujatha&#39;,&#39;Einthir


manithan&#39;,1,12);

insert into s2.dbo.Books values(newid(),&#39;Sujatha&#39;,&#39;Sample&#39;,1,30);

insert into s3.dbo.Books values(newid(),&#39;Sujatha&#39;,&#39;Lalgudi&#39;,10,40);

insert into s4.dbo.Books values(newid(),&#39;Sujatha&#39;,&#39;Kanini&#39;,5,300);

select * from s1.dbo.Books

select * from s2.dbo.Books

select * from s3.dbo.Books

select * from s4.dbo.Books

insert into s1.dbo.BookStore


values(newid(),&#39;Chicago&#39;,&#39;IL&#39;,&#39;60661&#39;,10000);

insert into s2.dbo.BookStore


values(newid(),&#39;Boston&#39;,&#39;MA&#39;,&#39;2233&#39;,30000);

insert into s3.dbo.BookStore


values(newid(),&#39;Albany&#39;,&#39;NY&#39;,&#39;1134&#39;,60000);

81
insert into s4.dbo.BookStore
values(newid(),&#39;LasVegas&#39;,&#39;CA&#39;,&#39;5677&#39;,80000);

select * from s1.dbo.BookStore

select * from s2.dbo.BookStore

select * from s3.dbo.BookStore

select * from s4.dbo.BookStore

insert into s1.dbo.stock values((select StoreNo from s1.dbo.BookStore where


City=&#39;Chicago&#39;),

(select top 1 ISBN from s1.dbo.Books bs where bs.Topic=&#39;Einthir


manithan&#39;),12);

insert into s2.dbo.stock values((select StoreNo from s1.dbo.BookStore where


City=&#39;Boston&#39;),

(select top 1 ISBN from s1.dbo.Books where topic=&#39;Sample&#39;),12);

insert into s3.dbo.stock values((select StoreNo from s1.dbo.BookStore where


City=&#39;Albany&#39;),

(select top 1 ISBN from s1.dbo.Books where topic=&#39;Lalgudi&#39;),12);

insert into s4.dbo.stock values((select StoreNo from s1.dbo.BookStore where


City=&#39;LasVegas&#39;),

(select top 1 ISBN from s1.dbo.Books where topic=&#39;Kanini&#39;),12);

--details from books

select * from s1.dbo.Books union

select * from s2.dbo.Books union

select * from s3.dbo.Books union

select * from s4.dbo.Books

--details from bookstore

select * from s1.dbo.BookStore union

select * from s2.dbo.BookStore union

select * from s3.dbo.BookStore union

82
select * from s4.dbo.BookStore

--Details from stock

select * from s1.dbo.Stock union

select * from s2.dbo.Stock union

select * from s3.dbo.Stock union

select * from s4.dbo.Stock

--Find the total number of books in stock where price is between $15 and $55

Create view BooksView as

select * from s1.dbo.Books union

select * from s2.dbo.Books union

select * from s3.dbo.Books union

select * from s4.dbo.Books

select * from BooksView

Create view BookStoreView as

select * from s1.dbo.BookStore union

select * from s2.dbo.BookStore union

select * from s3.dbo.BookStore union

select * from s4.dbo.BookStore

select * from BookStoreView

Create view StockView as

83
select * from s1.dbo.Stock union

select * from s2.dbo.Stock union

select * from s3.dbo.Stock union

select * from s4.dbo.Stock

--Find the total number of books in stock where price is between $15 and $55

select sum(sv.Qty) from BooksView bv

inner join StockView sv on sv.ISBN=bv.ISBN

inner join BookStoreView bvs on bvs.StoreNo=sv.StoreNo

where bv.Price between 15 and 55

group by bv.ISBN

--Update the bookprice of bookNo=1234 from $45 to $55 at site S3.

update s3.dbo.books set price=55 where topic=&#39;Einthir manithan&#39;

--Find total number of book at site S2.

select sum(sv.Qty) from s2.dbo.books bv

inner join s2.dbo.Stock sv on sv.ISBN=bv.ISBN

inner join s2.dbo.books bvs on bvs.StoreNo=sv.StoreNo

group by bv.ISBN

84
RESULT:

Thus the distributed database has been executed successfully and the output is verified.

85
EX.NO:12 DEADLOCK DETECTION ALGORITHM FOR DISTRIBUTED

DATE: 07-05-2021

Aim:

To implement deadlock detection algorithm for distributed database using wait-for graph

Description:

There are five transactions T1, T2, T3, T4 and T5 with

T1 initiated at site S1 and spawning an agent at site S2

T2 initiated at site S3 and spawning an agent at site S1

T3 initiated at site S1 and spawning an agent at site S3

T4 initiated at site S2 and spawning an agent at site S3

T5 initiated at site S3

Wait For Graph:

86
CODINGS:

Connected to:

Oracle9i Release 9.0.1.1.1 - Production

JServer Release 9.0.1.1.1 - Production

SQL&gt; create table dd1(trans varchar(20),loc varchar2(10),wait varchar2(10),site

varchar2(10));

Table created.

SQL&gt; insert into dd1


values(&#39;t1&#39;,&#39;x1&#39;,&#39;x8&#39;,&#39;s1&#39;);

1 row created.

SQL&gt; insert into dd1


values(&#39;t1&#39;,&#39;x6&#39;,&#39;x2&#39;,&#39;s2&#39;);

1 row created.

SQL&gt; insert into dd1


values(&#39;t2&#39;,&#39;x4&#39;,&#39;x7&#39;,&#39;s2&#39;);

1 row created.

SQL&gt; insert into dd1 values(&#39;t2&#39;,&#39;x5&#39;,&#39;


&#39;,&#39;s3&#39;);

1 row created.

87
SQL&gt; insert into dd1
values(&#39;t3&#39;,&#39;x2&#39;,&#39;x7&#39;,&#39;s1&#39;);

1 row created.

SQL&gt; insert into dd1 values(&#39;t4&#39;,&#39;x7&#39;,&#39;


&#39;,&#39;s2&#39;);

1 row created.

SQL&gt; insert into dd1


values(&#39;t4&#39;,&#39;x8&#39;,&#39;x5&#39;,&#39;s3&#39;);

1 row created.

SQL&gt; insert into dd1


values(&#39;t5&#39;,&#39;x3&#39;,&#39;x7&#39;,&#39;s3&#39;);

1 row created.

SQL&gt; select * from dd1;

TRANS LOC WAIT SITE

t1 x1 x8 s1

t1 x6 x2 s2

t2 x4 x7 s2

t2 x5 s3

t3 x2 x7 s1

t4 x7 s2

t4 x8 x5 s3

t5 x3 x7 s3

8 rows selected.

SQL&gt; ed dd1;

SQL&gt; set serveroutput on;

SQL&gt; @dd1;

42 /

88
SELECT trans, lock1, wait

ERROR at line 3:

ORA-06550: line 3, column 15:

PL/SQL: ORA-00904: invalid column name

ORA-06550: line 3, column 1:

PL/SQL: SQL Statement ignored

ORA-06550: line 5, column 34:

PLS-00302: component &#39;LOCK1&#39; must be declared

PL/SQL: Item ignored

ORA-06550: line 2, column 9:

PLS-00341: declaration of cursor &#39;C1&#39; is incomplete or malformed

ORA-06550: line 14, column 4:

PL/SQL: Item ignored

ORA-06550: line 19, column 15:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 19, column 1:

PL/SQL: SQL Statement ignored

ORA-06550: line 23, column 10:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 23, column 1:

PL/SQL: Statement ignored

ORA-06550: line 26, column 9:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

89
ORA-06550: line 26, column 1:

PL/SQL: Statement ignored

ORA-06550: line 29, column 10:

PLS-00320: the declaration of the type of this expression is incomplete or

SQL&gt; ed dd1;

SQL&gt; @dd1;

42 /

ll(c) := ss.lock1;

ERROR at line 23:

ORA-06550: line 23, column 13:

PLS-00302: component &#39;LOCK1&#39; must be declared

ORA-06550: line 23, column 1:

PL/SQL: Statement ignored

SQL&gt; ed dd1;

SQL&gt; @dd1;

42 /

TRANS Lock wait

t1 x1 x8

t1 x6 x2

t2 x4 x7

t2 x5

t3 x2 x7

t4 x7

t4 x8 x5

t5 x3 x7

x5&lt;-x5deadlock occured

90
x2&lt;-x2deadlock occured

x7&lt;-x7deadlock occured

x7&lt;-x7deadlock occured

x7&lt;-x7deadlock occured

x8&lt;-x8deadlock occured

PL/SQL procedure successfully completed.

SQL&gt; ed dd2;

SQL&gt; @dd2;

37 /

TRANS Lock wait

t1 x1 x8

t3 x2 x7

PL/SQL procedure successfully completed.

SQL&gt; ed dd3;

SQL&gt; ed dd3;

SQL&gt; @dd3;

40 /

SELECT trans, lock1, wait

ERROR at line 3:

ORA-06550: line 3, column 15:

PL/SQL: ORA-00904: invalid column name

ORA-06550: line 3, column 1:

PL/SQL: SQL Statement ignored

ORA-06550: line 2, column 9:

PLS-00341: declaration of cursor &#39;C1&#39; is incomplete or malformed

ORA-06550: line 14, column 4:

91
PL/SQL: Item ignored

ORA-06550: line 19, column 15:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 19, column 1:

PL/SQL: SQL Statement ignored

ORA-06550: line 21, column 22:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 21, column 1:

PL/SQL: Statement ignored

ORA-06550: line 24, column 10:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 24, column 1:

PL/SQL: Statement ignored

ORA-06550: line 27, column 10:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 27, column 1:

PL/SQL: Statement ignored

ORA-06550: line 36, column 5:

PLS-00201: identifier &#39;E&#39; mu

SQL&gt; ed dd3;

SQL&gt; @dd3;

41 /

SELECT trans, lock1, wait

92
*

ERROR at line 3:

ORA-06550: line 3, column 15:

PL/SQL: ORA-00904: invalid column name

ORA-06550: line 3, column 1:

PL/SQL: SQL Statement ignored

ORA-06550: line 2, column 9:

PLS-00341: declaration of cursor &#39;C1&#39; is incomplete or malformed

ORA-06550: line 15, column 4:

PL/SQL: Item ignored

ORA-06550: line 20, column 15:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 20, column 1:

PL/SQL: SQL Statement ignored

ORA-06550: line 22, column 22:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 22, column 1:

PL/SQL: Statement ignored

ORA-06550: line 25, column 10:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 25, column 1:

PL/SQL: Statement ignored

ORA-06550: line 28, column 10:

PLS-00320: the declaration of the type of this expression is incomplete or

93
malformed

ORA-06550: line 28, column 1:

PL/SQL: Statement ignored

SQL&gt; ed dd3;

SQL&gt; @dd3;

41 /

TRANS Lock wait

t1 x6 x2

t2 x4 x7

t4 x7

x7&lt;-x7deadlock occured

no deadlock

PL/SQL procedure successfully completed.

SQL&gt; ed dd4;

SQL&gt; @dd4;

37 /

SELECT trans, loc, wait

ERROR at line 3:

ORA-06550: line 3, column 15:

PL/SQL: ORA-00904: invalid column name

ORA-06550: line 3, column 1:

PL/SQL: SQL Statement ignored

ORA-06550: line 2, column 9:

PLS-00341: declaration of cursor &#39;C1&#39; is incomplete or malformed

ORA-06550: line 14, column 4:

PL/SQL: Item ignored

94
ORA-06550: line 19, column 15:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 19, column 1:

PL/SQL: SQL Statement ignored

ORA-06550: line 21, column 22:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 21, column 1:

PL/SQL: Statement ignored

ORA-06550: line 24, column 10:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 24, column 1:

PL/SQL: Statement ignored

ORA-06550: line 27, column 10:

PLS-00320: the declaration of the type of this expression is incomplete or

malformed

ORA-06550: line 27, column 1:

PL/SQL: Statement ignored

SQL&gt; ed dd4;

SQL&gt; @dd4;

37 /

TRANS Lock wait

t2 x5

t4 x8 x5

t5 x3 x7

95
x5&lt;-x5deadlock occured

PL/SQL procedure successfully completed.

SQL&gt; ed dd1;

SQL&gt; @dd1;

42 /

TRANS Lock wait

t1 x1 x8

t1 x6 x2

t2 x4 x7

t2 x5

t3 x2 x7

t4 x7

t4 x8 x5

t5 x3 x7

x5&lt;-x5deadlock occured

x2&lt;-x2deadlock occured

x7&lt;-x7deadlock occured

x7&lt;-x7deadlock occured

x7&lt;-x7deadlock occured

x8&lt;-x8deadlock occured

PL/SQL procedure successfully completed.

SQL&gt;

DD1 :

declare

cursor c1 is

SELECT trans, loc, wait

FROM dd1;

96
type c_list is varray(20) of dd1.loc%type;

ll c_list:=c_list();

type c_list1 is varray(20) of dd1.wait%type;

l2 c_list1:=c_list1();

type c_list2 is varray(20) of dd1.trans%type;

t c_list:=c_list();

c integer := 0;

d integer :=0;

f integer :=0;

ss c1%rowtype;

begin

open c1;

dbms_output.put_line(&#39;TRANS &#39;||&#39; &#39;||&#39;Lock&#39;||&#39;


&#39;||&#39;wait&#39;);

loop

fetch c1 into ss;

exit when c1%notfound;

c := c+1;

ll.extend;

ll(c) := ss.loc;

f := f+1;

t.extend;

t(f) := ss.trans;

d :=d+1;

l2.extend;

l2(d) := ss.wait;

dbms_output.put_line(ss.trans||&#39; &#39;||ss.loc||&#39;

97
&#39;||ss.wait); end loop;

for i in 1 .. c loop

for j in 1 .. d loop

if ( ll(i) = l2(j)) then

if(ll(i) != &#39;-&#39;)then

dbms_output.put_line(ll(i)||&#39;&lt;-&#39;||l2(j)||&#39;deadlock occured&#39;);

end if;

end if;

end loop;

end loop;

end;

DD2:

declare

cursor c1 is

SELECT trans, loc, wait

FROM dd1

WHERE Site=&#39;s1&#39;;

type c_list is varray(10) of dd1.loc%type;

ll c_list:=c_list();

type c_list1 is varray(10) of dd1.wait%type;

l2 c_list1:=c_list1();

type c_list2 is varray(20) of dd1.trans%type;

t c_list:=c_list();

c integer := 0;

d integer :=0;

98
ss c1%rowtype;

begin

open c1;

dbms_output.put_line(&#39;TRANS &#39;||&#39; &#39;||&#39;Lock&#39;||&#39;


&#39;||&#39;wait&#39;);

loop

fetch c1 into ss;

exit when c1%notfound;

dbms_output.put_line(ss.trans||&#39; &#39;||ss.loc||&#39; &#39;||ss.wait);

c := c+1;

ll.extend;

ll(c) := ss.loc;

d :=d+1;

l2.extend;

l2(d) := ss.wait;

end loop;

for i in 1 .. c loop

for j in 1 .. d loop

if ( ll(i) = l2(j)) then

dbms_output.put_line(ll(i)||&#39;&lt;-&#39;||l2(j)||&#39;deadlock occured&#39;);

end if;

end loop;

end loop;

end;

DD3:

declare

cursor c1 is

99
SELECT trans, loc, wait

FROM dd1

WHERE Site=&#39;s2&#39;;

type c_list is varray(10) of dd1.loc%type;

ll c_list:=c_list();

type c_list1 is varray(10) of dd1.wait%type;

l2 c_list1:=c_list1();

type c_list2 is varray(20) of dd1.trans%type;

t c_list:=c_list();

c integer := 0;

d integer :=0;

e integer :=0;

ss c1%rowtype;

begin

open c1;

dbms_output.put_line(&#39;TRANS &#39;||&#39; &#39;||&#39;Lock&#39;||&#39;


&#39;||&#39;wait&#39;);

loop

fetch c1 into ss;

exit when c1%notfound;

dbms_output.put_line(ss.trans||&#39; &#39;||ss.loc||&#39; &#39;||ss.wait);

c := c+1;

ll.extend;

ll(c) := ss.loc;

d :=d+1;

l2.extend;

l2(d) := ss.wait;

100
end loop;

for i in 1 .. c loop

for j in 1 .. d loop

if ( ll(i) = l2(j)) then

dbms_output.put_line(ll(i)||&#39;&lt;-&#39;||l2(j)||&#39;deadlock occured&#39;);

end if;

end loop;

end loop;

if (e = 0) then

dbms_output.put_line(&#39;no deadlock &#39;);

end if;

end;

DD4:

declare

cursor c1 is

SELECT trans, loc, wait

FROM dd1

WHERE Site=&#39;s3&#39;;

type c_list is varray(10) of dd1.loc%type;

ll c_list:=c_list();

type c_list1 is varray(10) of dd1.wait%type;

l2 c_list1:=c_list1();

type c_list2 is varray(20) of dd1.trans%type;

t c_list:=c_list();

c integer := 0;

d integer :=0;

101
ss c1%rowtype;

begin

open c1;

dbms_output.put_line(&#39;TRANS &#39;||&#39; &#39;||&#39;Lock&#39;||&#39;


&#39;||&#39;wait&#39;);

loop

fetch c1 into ss;

exit when c1%notfound;

dbms_output.put_line(ss.trans||&#39; &#39;||ss.loc||&#39; &#39;||ss.wait);

c := c+1;

ll.extend;

ll(c) := ss.loc;

d :=d+1;

l2.extend;

l2(d) := ss.wait;

end loop;

for i in 1 .. c loop

for j in 1 .. d loop

if ( ll(i) = l2(j)) then

dbms_output.put_line(ll(i)||&#39;&lt;-&#39;||l2(j)||&#39;deadlock occured&#39;);

end if;

end loop;

RESULT:

Thus the program to execute deadlock detection algorithm for distributed database using

wait-for graph has been executed successfully and output is verified.

102

You might also like