You are on page 1of 58

DATA DEFINITION COMMANDS, DATA MANIPULATION COMMANDS FOR

EX.NO:1
INSERTING, DELETING, UPDATING ANDRETRIEVING TABLES AND
TRANSACTION CONTROL
DATE:
STATEMENTS

AIM :

To create table and Execute Data Definition Commands, Data Manipulation Commands for Inserting,Deleting, Updating And
Retrieving Tables and Transaction Control Statements

CREATION OF TABLE WITHOUT PRIMARY KEY:


SQL> create table emp1977(emp_no number(5),emp_name varchar2(30),dept_no
number(5),dept_name varchar2(10),date_of_join date);
Table created.
TABLE DESCRIPTION:
SQL> desc emp1977;
Name Null? Type

EMP_NO NUMBER(5)
EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
CREATION OF TABLE WITH PRIMARY KEY:
SQL> create table emp1978(emp_no number(5) primary key,emp_name varchar2(30),dept_nonumber(5),dept_name
varchar2(10),date_of_join date);
Table created.
TABLE DESCRIPTION:
SQL> desc emp1978;
Name Null? Type

EMP_NO NOT NULL NUMBER(5)


EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE

INSERTION OF TABLE VALUES:


SQL> insert into emp1978 values(346,'kannan', 22,'CSE','22-JUN-07');1 row
created.
SQL> insert into emp1978 values(99,'kamal',23,'IT','29-SEP-07');1 row
created.
SQL> insert into emp1978 values(101,'kavitha',68,'CSE','14-NOV-82');1 row created.
SQL> insert into emp1978 values(127,'ravi',88,'ECE','26-DEC-07');1 row
created.
SELECTION OR DISPLAY OF TABLE:
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J
-
346 kannan 22 CSE 22-JUN-07
99 kamal 23 IT 29-SEP-07
101 kavitha 68 CSE 14-NOV-82
127 ravi 88 ECE 26-DEC-07
SQL> update emp1978 set emp_no=202 where dept_no=68;1 row
updated.
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

346 kannan 22 CSE 22-JUN-07


99 kamal 23 IT 29-SEP-07
202 kavitha 68 CSE 14-NOV-82
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
INSERTION OF TABLE VALUES:
SQL> insert into emp1977 values(99,'hari',79,'IT','25-DEC-08');1 row
created.
SQL> insert into emp1977 values(127,'priya',89,'ECE','11-SEP-09');1 row
created.
SQL> insert into emp1977 values(129,'lalitha',46,'ECE','24-SEP-10');1 row created.
SQL> select *from emp1977;

EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

99 hari 79 IT 25-DEC-08
127 priya 89 ECE 11-SEP-09
129 lalitha 46 ECE 24-SEP-10

SQL> select *from emp1978;


EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J
-
346 kannan 22 CSE 22-JUN-07
99 kamal 23 IT 29-SEP-07
202 kavitha 68 CSE 14-NOV-82
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
USING ALTER COMMAND:
SQL> alter table emp1978 drop primary key;Table
altered.
SQL> desc emp1978;
Name Null? Type

EMP_NO NUMBER(5)
EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
SQL> alter table emp1977 add primary key(emp_no);Table
altered.
SQL> desc emp1977;
Name Null? Type

EMP_NO NOT NULL NUMBER(5)


EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05

SQL> select *from emp1977;


EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

99 hari 79 IT 25-DEC-08
127 priya 89 ECE 11-SEP-09
129 lalitha 46 ECE 24-SEP-10

RESULT:

Thus, The table is created and Data Definition Commands, Data Manipulation Commands for Inserting,
Deleting, Updating And Retrieving Tables are successfully executed.
EX.NO:2
ADD FOREIGN KEY CONSTRAINTS AND INCORPORATE REFERENTIAL
INTEGRITY
DATE:

AIM :

To create table and Execute Data Definition Commands, Data Manipulation Commands to add foreign key constraints and
incorporate referential integrity Statements.
CREATION OF TABLE WITHOUT PRIMARY KEY:
SQL> create table emp1977(emp_no number(5),emp_name varchar2(30),dept_no
number(5),dept_name varchar2(10),date_of_join date);
Table created.
TABLE DESCRIPTION:
SQL> desc emp1977;
Name Null? Type

EMP_NO NUMBER(5)
EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
CREATION OF TABLE WITH PRIMARY KEY:
SQL> create table emp1978(emp_no number(5) primary key,emp_name varchar2(30),dept_nonumber(5),dept_name
varchar2(10),date_of_join date);
Table created.
TABLE DESCRIPTION:
SQL> desc emp1978;
Name Null? Type

EMP_NO NOT NULL NUMBER(5)


EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE

INSERTION OF TABLE VALUES:


SQL> insert into emp1978 values(346,'kannan', 22,'CSE','22-JUN-07');1 row
created.
SQL> insert into emp1978 values(99,'kamal',23,'IT','29-SEP-07');1 row
created.
SQL> insert into emp1978 values(101,'kavitha',68,'CSE','14-NOV-82');1 row created.
SQL> insert into emp1978 values(127,'ravi',88,'ECE','26-DEC-07');1 row
created.
SELECTION OR DISPLAY OF TABLE:
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J
-
346 kannan 22 CSE 22-JUN-07
99 kamal 23 IT 29-SEP-07
101 kavitha 68 CSE 14-NOV-82
127 ravi 88 ECE 26-DEC-07
SQL> update emp1978 set emp_no=202 where dept_no=68;1 row
updated.
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

346 kannan 22 CSE 22-JUN-07


99 kamal 23 IT 29-SEP-07
202 kavitha 68 CSE 14-NOV-82
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
INSERTION OF TABLE VALUES:
SQL> insert into emp1977 values(99,'hari',79,'IT','25-DEC-08');1 row
created.
SQL> insert into emp1977 values(127,'priya',89,'ECE','11-SEP-09');1 row
created.
SQL> insert into emp1977 values(129,'lalitha',46,'ECE','24-SEP-10');1 row created.
SQL> select *from emp1977;

EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

99 hari 79 IT 25-DEC-08
127 priya 89 ECE 11-SEP-09
129 lalitha 46 ECE 24-SEP-10

SQL> select *from emp1978;


EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J
-
346 kannan 22 CSE 22-JUN-07
99 kamal 23 IT 29-SEP-07
202 kavitha 68 CSE 14-NOV-82
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
USING ALTER COMMAND:
SQL> alter table emp1978 drop primary key;Table
altered.
SQL> desc emp1978;
Name Null? Type

EMP_NO NUMBER(5)
EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
SQL> alter table emp1977 add primary key(emp_no);Table
altered.
SQL> desc emp1977;
Name Null? Type

EMP_NO NOT NULL NUMBER(5)


EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05

SQL> select *from emp1977;


EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

99 hari 79 IT 25-DEC-08
127 priya 89 ECE 11-SEP-09
129 lalitha 46 ECE 24-SEP-10

CREATING FOREIGN KEY USING ALTER COMMAND:


SQL> alter table emp1978 add foreign key(emp_no) references emp1977(emp_no);Table
altered.
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
ADDING CONSTRAINTS TO TABLE:
SQL> alter table emp1978 add (salary number);Table
altered.
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J SALARY

99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
SQL> update emp1978 set salary=3000 where emp_no=99;1 row
updated.
SQL> update emp1978 set salary=2000 where emp_no=127;1 row
updated.
SQL> update emp1978 set salary=1800 where emp_no=129;
1 row updated.
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J SALARY

99 kamal 23 IT 29-SEP-07 3000


127 ravi 88 ECE 26-DEC-07 2000
129 nirmal 90 ECE 16-JUN-05 1800

DELETION OF TABLE VALUES:


SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

346 kannan 22 CSE 22-JUN-07


99 kamal 23 IT 29-SEP-07
202 kavitha 68 CSE 14-NOV-82
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
SQL> delete from emp1978 where emp_no=346;1 row
deleted.
SQL> delete from emp1978 where emp_no=202;1 row
deleted.
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J

99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
RENAMING TABLE:
SQL> rename emp1978 to emp1979;Table
renamed.
TRUNCATION OF TABLE:
SQL> truncate table emp1979;Table
truncated.
SQL> select *from emp1979;no
rows selected DROPPING OF
TABLE:
SQL> drop table emp1979;
Table dropped.

CREATION OF TABLE:
SQL> create table emp1982(emp_no number(5)primary key,emp_name varchar2(20), dept_nonumber(5),dept_name
varchar2(20));
Table created.
SQL> create table emp1983(emp_no number(5)primary key,emp_name varchar2(20),dept_nonumber(5),dept_name
varchar2(20));
Table created.
DESCRIPTION OF TABLE:
SQL> desc emp1982;
Name Null? Type

EMP_NO NOT NULL NUMBER(5)


EMP_NAME VARCHAR2(20)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
SQL> desc emp1983;
Name Null? Type

EMP_NO NOT NULL NUMBER(5)


EMP_NAME VARCHAR2(20)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)

SELECTION OF TABLE VALUES:


SQL> select *from emp1982;

EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


878 Nirmal 86 EEE
991 Rajesh 96 ME
SQL> select *from emp1983;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


477 Dinesh 56 IT
987 Yuvaraj 76 ECE

COMMIT & ROLLBACK COMMAND:


SQL> select *from emp1982;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


878 Nirmal 86 EEE
991 Rajesh 96 ME
SQL> commit; Commit
complete.
SQL> delete from emp1982 where dept_no=96;1 row
deleted.

SQL> select *from emp1982;


EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


878 Nirmal 86 EEE

SQL> rollback;
Rollback complete.
SQL> select *from emp1982;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


878 Nirmal 86 EEE
991 Rajesh 96 ME

SAVEPOINT & ROLLBACK COMMAND:


SQL> select *from emp1982;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


878 Nirmal 86 EEE
991 Rajesh 96 ME
SQL> savepoint Nirmal;
Savepoint created.
SQL> update emp1982 set dept_no=78 where emp_no=235;1 row
updated.
SQL> delete from emp1982 where emp_no=991;1 row
deleted.
SQL> select *from emp1982;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 78 CSE


878 Nirmal 86 EEE

SQL> roll back NIrmal;


Rollback complete.
SQL> select *from emp1982;

EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


878 Nirmal 86 EEE
991 Rajesh 96 ME

ARITHMETIC OPERATIONS:
SQL> select *from emp1982;

EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


878 Nirmal 86 EEE
991 Rajesh 96 ME

SQL> select sum(emp_no) from emp1982;


SUM(EMP_NO)

2104
SQL> select avg(emp_no) from emp1982;
AVG(EMP_NO)

701.333333
SQL> select max(emp_no) from emp1982;
MAX(EMP_NO)

991
SQL> select min(emp_no) from emp1982;
MIN(EMP_NO)

235
SQL> select count(emp_no) from emp1982;
COUNT(EMP_NO)

SET OPERATORS:
SQL> select *from emp1982;

EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


878 Nirmal 86 EEE
991 Rajesh 96 ME

SQL> select *from emp1983;


EMP_NO EMP_NAME DEPT_NO DEPT_NAME

235 Kannan 46 CSE


477 Dinesh 56 IT
987 Yuvaraj 76 ECE

SQL> select dept_no from emp1982 union select dept_no from emp1983;DEPT_NO
46
56
76
86
96
SQL> select dept_no from emp1982 union all select dept_no from emp1983;DEPT_NO
46
86
96
46
56
76
6 rows selected.
SQL> select dept_no from emp1982 intersect select dept_no from emp1983;DEPT_NO
46
SQL> select dept_no from emp1982 minus select dept_no from emp1983;DEPT_NO

86
96

RESULT:

Thus, The table is created and Data Definition Commands, Data Manipulation Commands for Inserting,
Deleting, Updating And Retrieving Tables and Transaction Control Statementsare successfully executed.
EX.NO:4
DATABASE QUERYING – SIMPLE QUERIES, NESTED QUERIES,SUB QUERIES
DATE: AND JOINS

AIM:

To Create Table and Apply Simple Queries Nested Queries, Sub Queries and Joins.

CREATION OF TABLE:

SQL> create table employee601(employee_name varchar2(15),employee_no number primarykey,dept_no numb


er,dept_name varchar2(10));

Table created.

SQL> insert into employee601 values('Ganesh',254,46,'CSE');1 row

created.

SQL> insert into employee601 values('Vijay',877,86,'EEE');1 row

created.

SQL> insert into employee601 values('Vignesh',991,96,'ME');1 row

created.

SQL> select * from employee601;

EMPLOYEE_NAME EMPLOYEE_NO DEPT_NO DEPT_NAME

Ganesh 254 46 CSE


Vijay 877 86 EEE
Vignesh 991 96 ME

SQL> create table employee702(employee_name varchar2(15),employee_no number primarykey,dept_no


number,dept_name varchar2(10));

Table created.

SQL> insert into employee702 values('Ganesh',254,46,'CSE');1 row

created.

SQL> insert into employee702 values('Vishnu',477,56,'IT');1 row

created.

SQL> insert into employee702 values('Vikram',986,76,'ECE');


1 row created.
SQL> select * from employee702;

EMPLOYEE_NAME EMPLOYEE_NO DEPT_NO DEPT_NAME

Ganesh 254 46 CSE


Vishnu 477 56 IT
Vikram 986 76 ECE
JOIN COMMANDS:

SQL>alter table employee702 add foreign key(employee_no) references employee702 (employee_no)Table altered.

SUB QUERY:

SQL> update employee601 set dept_no=(select sum(employee_no) from employee601) whereemployee_no=254

1 row updated.

SQL> select * from employee601;

EMPLOYEE_NAME EMPLOYEE_NO DEPT_NO DEPT_NAME

Ganesh 254 2122 CSE


Vijay 877 86 EEE
Vignesh 991 96 ME

OUTER JOIN:

SQL>create table emp908(emp_name varchar2(20),city varchar2(16));SQL>

insert into emp908 values('Hari','Pune');

1 row created.

SQL> insert into emp908 values('Om','Mumbai');1 row

created.

SQL> insert into emp908 values('Smith','Nashik');1 row

created.

SQL> insert into emp908 values('Jay','Solapur');1 row

created.

SQL> select * from emp908;


EMP_NAME CITY

Hari Pune
Om Mumbai
Smith Nashik
Jay Solapur

SQL> create table empsal608(emp_name varchar2(20),dept varchar2(15),salary number(6));Table

created.

SQL> insert into empsal608 values('Hari','Computer',10000);1 row

created.

SQL> insert into empsal608 values('Om','IT',7000);1 row

created.

SQL> insert into empsal608 values('Bill','Computer',8000);1 row

created.

SQL> insert into empsal608 values('Jay','IT',5000);1 row

created.

SQL> select * from empsal608;

EMP_NAME DEPT SALARY

Hari Computer 10000


Om IT 7000
Bill Computer 8000
Jay IT 5000

LEFT OUTER JOIN:

SQL> select e.emp_name,e.city,s.dept,s.salary from emp908 e,empsal608 s wheree.emp_name(+)=s.emp_name;

EMP_NAME CITY DEPT SALARY

Computer 8000
Hari Pune Computer 10000
Jay Solapur IT 5000
Om Mumbai IT 7000

RIGHT OUTER JOIN:


SQL> select e.emp_name,e.city,s.dept,s.salary from emp908 e,empsal608 s wheree.emp_name=s.emp_name(+);

EMP_NAME CITY DEPT SALARY

Hari Pune Computer 10000


Jay Solapur IT 5000
Om Mumbai IT 7000
Smith Nashik
INNER JOIN:

SQL> select e.emp_name,e.city,s.dept,s.salary from emp908 e,empsal608 s wheree.emp_name=s.emp_name;

EMP_NAME CITY DEPT SALARY

Hari Pune Computer 10000


Jay Solapur IT 5000
Om Mumbai IT 7000

ADDTIONAL QURIES:

SQL> select ABS(-15) "Absolute" from dual;

Absolute

15

SQL> select power(3,2) "Raised" from dual;Raised

SQL> select Round(15.19,1) "Round" from dual;Round

15.2

SQL> select SQRT(25) "SquareRoot" from dual;

SquareRoot

SQL> select lower('CSE') "Lower" from dual;

Low
---
cse

SQL> select initcap('CSE') "Title case" from dual;Tit


---
Cse

SQL> select upper('Ms.Carol') "Upper" from dual;Upper

MS.CAROL

SQL> select substr('ABCDEFG',2,3) "Substring" from dual;Sub


---
BCD

SQL> select length('cse') "LENGTH" from dual;LENGTH

3
SQL> select LTRIM('xxxXxxLAST','x') "LTRIM" from dual;

LTRIM

XxxLAST

SQL> select RTRIM('TURNERXxx','x') "RTRIM" from dual;RTRIM

TURNERX

SQL> select LPAD('Page 1',14,'*') "LPAD" from dual;LPAD

********Page 1

SQL> select RPAD('CSE',5,'*') "RPAD" from dual;RPAD

CSE**

RESULT:

Thus, The Tables are created and Simple Queries , Nested Queries, Sub Queries and Joins areapplied on the
tables.
EX.NO:3 VIEWS, SEQUENCES, SYNONYMS

DATE:

AIM:
To create database and apply Views, Sequences, Synonyms.
TABLE CREATED:

SQL> create table book11(bookno number(10),book_name varchar2(40),title


varchar(40),author_name varchar2(40));

Table created. SQL>

desc book11;

Name Null? Type

BOOKNO NUMBER(10)
BOOK_NAME VARCHAR2(40)
TITLE VARCHAR2(40)
AUTHOR_NAME VARCHAR2(40)

SQL>alter table book11 modify(author_name varchar2(35));Table

altered.

SQL> desc book11;

Name Null? Type

BOOKNO NUMBER(10)
BOOK_NAME VARCHAR2(40)
TITLE VARCHAR2(40)
AUTHOR_NAME VARCHAR2(35)

INSERTION OF TABLE VALUES:

SQL> insert into book11 values(&bookno,'&book_name','&title','&author_name');Enter value for


bookno: 1
Enter value for book_name: c
Enter value for title: Programming in C
Enter value for author_name: BALAGURASWAMY
old 1: insert into book11 values(&bookno,'&book_name','&title','&author_name') new 1: insert into
book11 values(1,'c','Programming in C','BALAGURASWAMY')1 row created.

SQL> /

Enter value for bookno: 2


Enter value for book_name: OOPS
Enter value for title: obj oriented programming
Enter value for author_name: BALAGURASWAMY
old 1: insert into book11 values(&bookno,'&book_name','&title','&author_name')new 1: insert into
book11 values(2,'OOPS','obj oriented programming','BALAGURASWAMY')
1 row created.

SQL> /
Enter value for bookno: 3
Enter value for book_name: dbms
Enter value for title: DATABASE TECHNOLOGYEnter value
for author_name: SCHILLER
old 1: insert into book11 values(&bookno,'&book_name','&title','&author_name')
new 1: insert into book11 values(3,'dbms','DATABASE TECHNOLOGY','SCHILLER')1 row created.

SQL> /

Enter value for bookno: 4


Enter value for book_name: SW
Enter value for title: SOFTWARE ENGG Enter
value for author_name: PRESSMAN
old 1: insert into book11 values(&bookno,'&book_name','&title','&author_name')new 1: insert into
book11 values(4,'SW','SOFTWARE ENGG','PRESSMAN')
1 row created.

SQL> /

Enter value for bookno: 5


Enter value for book_name: MM Enter
value for title: MULTIMEDIA
Enter value for author_name: KAVITHA
old 1: insert into book11 values(&bookno,'&book_name','&title','&author_name')new 1: insert into
book11 values(5,'MM','MULTIMEDIA','KAVITHA')
1 row created.

SELECTION OF TABLE VALUES:

SQL> select *from book11;

BOOKNO BOOK_NAME TITLE AUTHOR_NAME

1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
4 SW SOFTWARE ENGG PRESSMAN
5 mm MULTIMEDIA KAVITHA

CREATION OFVIEWS:

SQL> create view book_student as select bookno,book_name,title,author_name from book11;


View created.

SELECTING DATA FROM A VIEW:

SQL> select *from book_student;

-BOOKNO BOOK_NAME TITLE AUTHOR_NAME

1 c Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
4 SW SOFTWARE ENGG PRESSMAN
5 MM MULTIMEDIA KAVITHA

UPDATABLE VIEWS:

SQL> update book_student set book_name='C' where bookno=1;1 row

updated.

SQL> select *from book_student;

BOOKNO BOOK_NAME TITLE AUTHOR_NAME

1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
4 SW SOFTWARE ENGG PRESSMAN
5 MM MULTIMEDIA KAVITHA

SQL> update book_student set book_name='mm' where bookno=5;1 row


updated.

SQL> select *from book_student;

BOOKNO BOOK_NAME TITLE AUTHOR_NAME

1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
4 SW SOFTWARE ENGG PRESSMAN
5 mm MULTIMEDIA KAVITHA

DELETE THE VIEWS:

SQL> select *from book_student;

BOOKNO BOOK_NAME TITLE AUTHOR_NAME


1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
SQL> delete from book_student where book_name='dbms';1 row
deleted.

SQL> select *from book_student;

BOOKNO BOOK_NAME TITLE AUTHOR_NAME

1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY

DESTROYING A VIEW:

SQL> drop view book_student;View


dropped.

SQL> select *from book_student;select


*from book_student
* ERROR
at line 1:
ORA-00942: table or view does not exist

SEQUENCES:

Sequence is a set of integers 1, 2, 3, … that are generated and supported by some database systems toproduce unique
values on demand.

Example 1:
CREATE SEQUENCE sequence_1start
with 1
increment by 1
minvalue 0
maxvalue 100
cycle;

Above query will create a sequence named sequence_1.Sequence will start from 1 and will be incremented by 1
having maximum value 100. Sequence will repeat itself from start value afterexceeding 100.

Example 2:
Following is the sequence query creating sequence in descending order.

CREATE SEQUENCE sequence_2

start with 100 increment by -1 minvalue 1 maxvalue 100 cycle;

Above query will create a sequence named sequence_2.Sequence will start from 100 and should beless than or
equal to maximum value and will be incremented by -1 having minimum value 1.

Example to use sequence :


create a table named students with columns as id and name. CREATE

TABLE students( ID number(10),NAME char(20));Now insert values

into table

INSERT into students VALUES(sequence_1.nextval,'Ramesh');


INSERT into students VALUES(sequence_1.nextval,'Suresh');

Output:

| ID | NAME |

| 1 | Ramesh |
| 2 | Suresh |

SYNONYMS:

create public synonym suppliers for app.suppliers;

This first CREATE SYNONYM example demonstrates how to create a synonym called suppliers.Now, users of other
schemas can reference the table called suppliers without having to prefix the table name with the schema named
app. For example:

SELECT * FROM suppliers;

If this synonym already existed and you wanted to redefine it, you could always use the ORREPLACE
phrase as follows:

CREATE OR REPLACE PUBLIC SYNONYM suppliers FOR app.suppliers;Drop synonym

Once a synonym has been created in Oracle, you might at some point need to drop the synonym.

drop public synonym suppliers;

This DROP statement would drop the synonym called suppliers that we defined earlier.

RESULT:

Thus a database is created and and Views, Sequences, Synonyms are applied on the table.
EX.NO: 8
TRIGGERS
DATE:

AIM:

SQL> create table emp901(id number(3),name varchar(20),income number(4),expencenumber(4),savings


number(4));

Table created.

SQL> insert into emp901 values(1,'lalitha',5000,2500,2500);1 row

created.

SQL> insert into emp901 values(2,'kamal',6000,3000,3000);1 row

created.

SQL> insert into emp901 values(3,'rajesh',7500,3000,3500);1 row

created.

SQL> select * from emp901;

ID NAME INCOME EXPENCE SAVINGS

1 lalitha 5000 2500 2500


2 kamal 6000 3000 3000
3 rajesh 7500 3000 3500

BEFORE INSERT:

SQL> edit mur12.sql;

create or replace trigger vaijy before insert on emp901 for each rowdeclare
k integer;
begin
select count(*)into k from emp901;
if(k>=5)then
dbms_output.put_line('Add only Five record');end if;
end;

SQL> set serveroutput on;


SQL> start mur12.sql;
10 /
Trigger created.

SQL> insert into emp901 values(4,'kavi',8000,4000,4000);1 row

created.

SQL> insert into emp901 values(5,'mani',7600,4000,3600);1 row

created.

SQL> insert into emp901 values (6,'ashok',8600,4000,4600);Add only


Five record
1 row created.

SQL> select * from emp901;

ID NAME INCOME EXPENCE SAVINGS


-
1 lalitha 5000 2500 2500
2 kamal 6000 3000 3000
3 rajesh 7500 3000 3500
4 kavi 8000 4000 4000
5 mani 7600 4000 3600
6 ashok 8600 4000 4600

6 rows selected.

AFTER DELETE:

SQL> edit mur13.sql;

create or replace trigger vaily1 after delete on emp901 for each rowbegin
dbms_output.put_line('you are deleting the record');end;
SQL> set serveroutput on;
SQL> start mur13.sql;
5 /

Trigger created.

SQL> delete from emp901 where id=6;you


are deleting the record

1 row deleted.
SQL> select * from emp901;

ID NAME INCOME EXPENCE SAVINGS

1 lalitha 5000 2500 2500


2 kamal 6000 3000 3000
3 rajesh 7500 3000 3500
4 kavi 8000 4000 4000
5 mani 7600 4000 3600
AFTER UPDATE:

SQL> edit up15.sql;

create or replace trigger vijay2 after update on emp901 for each rowbegin
dbms_output.put_line('Updated successfully in your database');end;
SQL> set serveroutput on;
SQL> start up15.sql;
5 /
Trigger created.
SQL> update emp901 set name='murali' where id=5;Updated
successfully in your database

1 row updated.

SQL> select * from emp901;

ID NAME INCOME EXPENCE SAVINGS

1 lalitha 5000 2500 2500


2 kamal 6000 3000 3000
3 rajesh 7500 3000 3500
4 kavi 8000 4000 4000
5 murali 7600 4000 3600

AFTER INSERT

SQL> edit afin.sql;


create or replace trigger ven1 after insert on emp905 for each rowbegin
dbms_output.put_line('Do not enter more records');end;
SQL> set serveroutput on;
SQL> start afin.sql;
5 /

Trigger created.
SQL> insert into emp905 values(6,'ravi',9000,5000,4000);Do not
enter more records

1 row created.

SQL> select *from emp905;

ID NAME INCOME EXPENCE SAVINGS

1 liaitha 5000 2500 2500


2 kamal 6000 3000 3000
3 rajesh 7500 3000 3500
4 kavi 8000 4000 4000
5 murali 7600 4000 3600
6 ravi 9000 5000 4000
6 rows selected.

BEFORE DELETE:

SQL>edit bede.sql;

create or replace trigger ven4 before delete on emp905 for each rowbegin
dbms_output.put_line('Stop deleting records..');end;
SQL> set serveroutput on;
SQL> start bede.sql;
5 /

Trigger created.

SQL> delete from emp905 where id=6;Stop


deleting records..

1 row deleted.
ENABLING (OR) DISABLING TRIGGERS:

SQL> alter trigger vijay2 disable;

Trigger altered.

SQL> alter trigger vijay2 enable;

Trigger altered.

SQL> alter table emp905 enable all triggers;Table

altered.

DROPPING TRIGGER:

SQL> drop trigger vijay;

Trigger dropped.

RESULT:

Thus, The program for Triggers was successfully executed.


EX.NO:8 DATABASE DESIGN USING ER MODELING, NORMALIZATION ANDIMPLEMENTATION
FOR ANY APPLICATION
DATE:

AIM:
To design a database using ER Modeling and implement Normalization for an Application.

CONCEPT DESIGN WITH E-R MODEL:

AIM: To Relate the entities appropriately. Apply cardinalities for each relationship. Identify strongand weak entities.
Indicate the type of relationships (total/partial). Incorporate generalization, aggregation and specialization etc
wherever required.

E-R Model
Bus
 BusNo
 Source
 Destination
 CoachType

SCHEMA
Bus: Bus(BusNo :String ,Source : String, Destination: String, Coach Type: String)

Ticket
 TicketNo
 DOJ
 Address
 ContactNo
 BusNo
Passenger
 PassportID
 TicketNo
 Name
 ContactNo
 Age
 Sex
 Address
SCHEMA
Passenger (PassportID: String, TicketNo :string, Name: String, ContactNo: string, Age:integer, Sex: character,
Address: String)

Reservation
 PNRNo
 DOJ
 No_of_seats
 Address
 ContactNo
 BusNo
 SeatNo
SCHEMA
Reservation(PNRNo: String, DOJ: Date, NoofSeats: integer , Address: String ,ContactNo: String, ,BusNo: String,SeatNo:Integer)

Cancellation
 PNRNo
DOJ
 SeatNo
 ContactNo
 Status

SCHEMA
Cancellation (PNRNo: String, DOJ: Date, SeatNo: integer, ContactNo: String, Status:String)
CONCEPT DESIGN WITH E-R MODEL
NORMALIZATION

AIM: Apply the database Normalization techniques for designing relational database tables tominimize duplication of
information like 1NF, 2NF, 3NF, BCNF.

Normalization is a process of converting a relation to be standard form by decomposition a largerrelation


intosmaller efficient relation that depicts a good database design.

 1NF: A Relation scheme is said to be in 1NF if the attribute values in the relation areatomic.i.e., Mutli
–valued attributes are not permitted.

 2NF: A Relation scheme is said to be in 2NF,iff and every Non-key attribute is fullyfunctionally
dependent on primary Key.

 3NF: A Relation scheme is said to be in 3NF,iff and does not have transitivity dependencies.A Relation is
said to be 3NF if every determinant is a key for each & every functional dependency

 BCNF: A Relation scheme is said to be BCNF if the following statements are true for eacg FDP->Q in set F
of FDs that holds for each FD. P->Q in set F of FD's that holds over R. Here P isthe subset of attributes of
R & Q is a single attribute of R.

 The given FD is a trival.

 P is a super key.


Normalized tables are:-

SQL> create table Bus2(BusNo varchar(20) primary key,Source varchar(20),Destination varchar(20));

SQL>Create table passenger4(PPN varchar(15) Primary key,Name varchar(20),Age integer,Sexchar,Address


varchar(20));

SQL> Create table PassengerTicket(PPN varchar(15) Primary key,TicketNo integer);

SQL> Create table Reservation2(PNRNO integer Primary key, JourneyDate DateTime,NoofSeatsint,Address


varchar(20),ContactNo Integer);

SQL> create table Cancellation2(PNRNO Integer primary key,JourneyDate DateTime,NoofSeatsInteger,Address


varchar(20),ContactNo Integer,foreign key(PNRNO) references Reservation2(PNRNO));

SQL> Create table Ticket2(TicketNo Integer Primary key,JourneyDate DateTime, Age Int(4),Sexchar(2),Source
varchar(20),Destination varchar(20),DeptTime varchar(2));

RESULT:

Thus a table is designed for a database using ER Modeling and Normalization isimplemented for
Passenger Application.
EX.NO:9A
DATABASE CONNECTIVITY WITH FRONT END TOOLS
DATE:

AIM :

To use Visual Basic tools and components.

EXECUTION:

FORM1

Private Sub Command1_Click()


List1.AddItem Text1.Text List1.AddItem
Text2.Text
If Option1.Value = True Then
gender = "Male"
End If
If Option2.Value = True Then
gender = "Female"
End If
List1.AddItem gender List1.AddItem
Text3.Text
If Check1.Value = 1 And Check2.Value = 0 Thenarea =
"Java"
End If
If Check1.Value = 1 And Check2.Value = 1 Thenarea =
"Java & Networks"
End If
If Check1.Value = 0 And Check2.Value = 1 Thenarea =
"Networks"
End If List1.AddItem
area
List1.AddItem Text4.TextEnd
Sub

Private Sub Command2_Click()


List1.Clear
End Sub

Private Sub Command3_Click()End


End Sub
SAMPLE OUTPUT:
FORM DESIGN

VB CODINGS:
Private Sub ADD_Click()
Dim a As Integer
a = Val(Text1.Text) + Val(Text2.Text)
MsgBox ("Addition of Two numbers is" + Str(a))End
Sub

Private Sub DIV_Click()


Dim d As Integer
d = Val(Text1.Text) / Val(Text1.Text)
MsgBox ("Division of Two numbers is" + Str(d))End
Sub

Private Sub EXIT_Click()End


End Sub

Private Sub MUL_Click()


Dim c As Integer
c = Val(Text1.Text) * Val(Text2.Text)
MsgBox ("Multiplication of Two numbers is" + Str©)End Sub

Private Sub SUB_Click()


Dim a As Integer
b = Val(Text1.Text) – (Text2.Text)
MsgBox ("Subraction of Two numbers is" + Str(b))End
Sub
OUTPUT:
MENU DESIGN

VB CODINGS

Private Sub Apple_Click(Index As Integer)


MsgBox ("You Select The Apple")
End Sub

Private Sub Blue_Click(Index As Integer)


MsgBox ("You Select The Blue")
End Sub

Private Sub Circle_Click(Index As Integer)


MsgBox ("You Select The Circle")
End Sub

Private Sub Exit_Click(Index As Integer)Unload


Me
End Sub

Private Sub Grapes_Click(Index As Integer)


MsgBox ("You Select The Grapes")
End Sub

Private Sub Orange_Click(Index As Integer)


MsgBox ("You Select The Orange")
End Sub

Private Sub Rectangle_Click(Index As Integer)


MsgBox ("You Select The Rectangle")
End Sub

Private Sub Red_Click(Index As Integer)


MsgBox ("You Select The Red")
End Sub

Private Sub Triangle_Click(Index As Integer)


MsgBox ("You Select The Triangle")
End Sub

Private Sub Yellow_Click(Index As Integer)


MsgBox ("You Select The Yellow")
End Sub
SAMPLE SNAPSHOT:

RESULT:

Thus, Visual Basic Tools were applied in the program.


REPORT GENERATION

SQL> create table payrol555 (ename varchar2(20),eno number,designation varchar2(20),sexvarchar2(1),age


number,basicsal number(15,5),da number(15,5),hra number(15,5),pf number(15,5),salary number(15,5));
Table created.
SQL> select * from payrol5655;

ENAME ENO DESIGNATION SEX AGE BASICSAL DA HRA PF SALARY


-
Kala 1001 Manager F 27 2000 500 100 300 6700
Balu 1002 MD M 35 5000 2000 500 750 6750
Mohan 1003 AssManager M 45 10000 4000 1000 1500 13500

SAMPLE OUTPUT:
Private Sub Command1_Click()
DataReport1.Show
End Sub
EX.NO:9B
DATABASE CONNECTIVITY WITH FRONT END TOOLS
DATE:

AIM:

To connect MS-ACCESS back end Database with Visual Basic Front end Tool.

Create a dataset for a .mdb file

Connect to databases created with Access 2000-2003 by using the following procedure.

1. Open a Windows Forms or WPF application project in Visual Studio.


2. On the View menu, select Other Windows > Data Sources.
3. In the Data Sources window, click Add New Data Source.

The Data Source Configuration Wizard opens.

4. Select Database on the Choose a Data Source Type page, and then select Next.
5. Select Dataset on the Choose a Database Model page, and then select Next.
6. On the Choose your Data Connection page, select New Connection to configure a newdata connection.
7. If the data source is not Microsoft Access Database File (OLE DB), select Change to openthe Change
Data Source dialog box and select Microsoft Access Database File, and then select OK.
8. In the Database file name, specify the path and name of the .mdb file you want to connectto, and then
select OK.

9. Select Next on the Choose your Data Connection page.


10. Select Next on the Save connection string to the Application Configuration file page.
11. Expand the Tables node on the Choose your Database Objects page.
12. Select whatever tables or views you want in your dataset, and then select Finish.

The dataset is added to your project, and the tables and views appear in the Data Sources
window.

In the Visual Basic , do the following steps:


1. Open Visual Basic 6.0 in Standard EXE mode.
2. Create Labels and textboxes on the form as needed
3. Right click on Tools menu
4. Select Components
5. Check in the box of Microsoft OLE DB provider
6. Click OK
7. Go to project Menu. Click on References
8. Add Microsoft ActiceX data Control 2.8 Library and click OK
9. Drag and drop the ADO Control on the Form
10. Right Click on the ADO Control and Click in the "USE CONNECTION STRING" option box
11. Click on Build
12. Select the database from MS Access and then choose Record source tab.
13. Slect 2. AMDTable
14. And select the table name from MS Access.
15. Click APPLY and then OK
16. Now go to text box and select property window
17. Set the Datasource value as ADODC and Data field as the first field of the table.
18. And select next textbox and goto property window.
19. Set the Datasource value as ADODC and Data field as the second field of the table and so on.
20. Then execute the form

Now the table from the MS Access database is now connected to the form designed.

ScreenShots:
Use the ADO Data Control to create a Connection
The first step in using the ADO Data Control to create a Connection to a database is to find the ADOData Control. By
default, the DAO Data Control is contained in the Visual Basic Toolbox, so you'll need to select Project- Components
from the Visual Basic Menu Bar, and select the Microsoft ActiveX Data Control…

If you click on the OK button, the ActiveX Data Control will then appear in the form.
RESULT :

Thus the database table in the MS-ACCESS is now connected to the Visual Basic 6.0successfully through ADO
Control.
CASE STUDY USING REAL LIFE DATABASE
EX.NO:10A
APPLICATIONS

DATE: PAYROLL PROCESSING

AIM:

To develop a Payroll Processing System using Oracle as s back end(data base) and Microsoft Visualbasic as a front
end.

SQL> create table pay1982(eno number,ename varchar(20),designation varchar(20),sexvarchar(1),age


number,basicsal number(15,5),da number(15,5),hra number(15,5),pf number(15,5),salary number(15,5));

Table created.

SQL> desc pay1982;


Name Null? Type

ENO NUMBER
ENAME VARCHAR2(20)
DESIGNATION VARCHAR2(20)
SEX VARCHAR2(1)
AGE NUMBER
BASICSAL NUMBER(15,5)
DA NUMBER(15,5)
HRA NUMBER(15,5)
PF NUMBER(15,5)
SALARY NUMBER(15,5)

SQL> insert into pay1982 values(101,'anitha','Manager','F',35,2000,500,100,300,6700);1 row created.

SQL> commit; Commit


complete.

SQL> select *from pay1982;

ENO ENAME DESIGNATION S AGE BASICSAL DA HRA PF


SALARY

101 anitha Manager F 35 2000 500 100 300


6700
VB CODINGS:

Private Sub ADD_Click()


Text1.SetFocus
Adodc1.Recordset.AddNewEnd Sub

Private Sub DA_Click() Dim


TEMP1 As Variant TEMP1 =
Val(Text1.Text)
Text7.Text = Val(TEMP1 * 0.4)
Adodc1.Recordset.Update
End Sub

Private Sub DELETE_Click()


If Adodc1.Recordset.EOF And Adodc1.Recordset.BOF ThenMsgBox
"No Record To Delete"
Else Adodc1.Recordset.DELETE
Adodc1.Recordset.MoveNext
MsgBox "Record Deleted" End If
End Sub

Private Sub EXIT_Click()End


End Sub

Private Sub HRA_Click() Dim


TEMP2 As Variant TEMP2 =
Val(Text6.Text)
Text8.Text = Val(TEMP2 * 0.1)
Adodc1.Recordset.Update
End Sub

Private Sub PF_Click() Dim


TEMP3 As Variant TEMP3 =
Val(Text6.Text)
Text9.Text = Val(TEMP3 * 0.15)
Adodc1.Recordset.Update
End Sub

Private Sub SAL_Click() Dim


TEMP4 As Variant TEMP4 =
Val(Text6.Text)
Text10.Text = Str(Val(Text6.Text) + Val(Text7.Text) + Val(Text8.Text) - Val(Text9.Text))
Adodc1.Recordset.Update
End Sub

Private Sub SAVE_Click()


Adodc1.Recordset.SAVE
MsgBox "Record Saved" End
Sub
SAMPLE OUTPUT:

RESULT
A Payroll Processing System using Oracle as s back end(data base) and Microsoft Visual basicas a front
end is developed and executed successfully.
EX.NO:10B CASE STUDY USING REAL LIFE DATABASE
APPLICATIONSBANKING SYSTEM
DATE:

AIM:

To develop a Banking System using Oracle as s back end(data base) and Microsoft Visual basicas a front end.

SQL> create table bank82(accno number(10),name varchar(25),address varchar(25),balancenumber(20));

Table created.

SQL> desc bank82;


Name Null? Type

ACCNO NUMBER(10)
NAME VARCHAR2(25)
ADDRESS VARCHAR2(25)
BALANCE NUMBER(20)

SQL> insert into bank82 values(&accno,'&name','&address',&balance); Enter value


for accno: 1001
Enter value for name: revathi
Enter value for address: big st
Enter value for balance: 1000
old 1: insert into bank82 values(&accno,'&name','&address',&balance) new 1: insert
into bank82 values(1001,'revathi','big st',1000)

1 row created.

SQL> /
Enter value for accno: 1002 Enter
value for name: kavi Enter value
for address: koil stEnter value for
balance: 2000
old 1: insert into bank82 values(&accno,'&name','&address',&balance)new 1: insert into
bank82 values(1002,'kavi','koil st',2000)

1 row created. SQL>

commit; Commit

complete.
SQL> select *from bank82;

ACCNO NAME ADDRESS BALANCE


1001 revathi big st 1000
1002 kavi koil st 2000

VB CODINGS:

Dim DEP As Integer Dim WD


As Integer Private Sub
ADD_Click()
Adodc1.Recordset.AddNew
Text1.SetFocus
End Sub

Private Sub DEPOSIT_Click()


DEP = InputBox("Enter The Amount")End
Sub

Private Sub EXIT_Click()End


End Sub

Private Sub SAVE_Click()


Adodc1.Recordset.SAVE
MsgBox "Record Saved" End
Sub

Private Sub UPDATE_DEP_Click(Index As Integer)


Text4.Text = Val(Text4.Text) + DEP Adodc1.Recordset.Update
MsgBox "Record Updated"End
Sub

Private Sub UPDATE_WITH_Click(Index As Integer)


Text4.Text = Val(Text4.Text) - WD Adodc1.Recordset.Update
MsgBox "Record Updated"End
Sub

Private Sub WITHDRAW_Click() WD =


InputBox("Enter The Amount")End Sub
OUTPUT:
RESULT:

Thus a Banking System using Oracle as s back end(data base) and Microsoft Visual basic as afront end is
developed and executed successfully.

You might also like