Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 80

Ex.

No:1(a) DATA DEFINITION LANGUAGE

AIM:
To execute and verify the Data Definition Language commands
a) CREATE TABLE COMMAND:
Syntax:
Create table tablename [column name datatype (size)…… column name datatype (size)];
Description :
The create table statement is used to create a table in database
Query:
SQL> create table classa (sid number (5) primary key, sname varchar2 (10), sdept varchar2 (10),
total number (5));
Output:
Table created.
SQL> desc classa;
Name Null? Type
----------------------------------------- -------- ----------------------------
SID NOT NULL NUMBER(5)
SNAME VARCHAR2(10)
SDEPT VARCHAR2(10)
TOTAL NUMBER(5)

b) ALTER TABLE QUERY:


Used to change a table without removing it from the database.The alter table statements
can be used to
(i) Adding new columns to the existing database:
Syntax:
Alter table table name ADD [new column name datatype (size)…new column name datatype
(size)…);
Description :
To add a column into a database
Query:
SQL> alter table classa add(grade varchar2(10));
Output:
Table altered.
SQL> desc classa;
Name Null? Type
----------------------------------------- -------- ----------------------------
SID NOT NULL NUMBER(5)
SNAME VARCHAR2(10)
SDEPT VARCHAR2(10)
TOTAL NUMBER(5)
GRADE VARCHAR2(10)

(ii) Redefine the column size:


Syntax:
Alter table tablename modify (datatype (size));
Description :
To change the data type of column.
Query:
SQL> SQL> alter table classa modify ( sname varchar2(15));
Output:
Table altered.
SQL> desc classa;
Name Null? Type
----------------------------------------- -------- ----------------------------
SID NOT NULL NUMBER(5)
SNAME VARCHAR2(15)
SDEPT VARCHAR2(10)
TOTAL NUMBER(5)
GRADE VARCHAR2(10)

(iii) Delete a Column :


Syntax:
Alter table tablename drop (column name);
Description :
To delete a column.
Query:
SQL> alter table classa drop(grade);
Output:
Table altered.
SQL> desc classa;
Name Null? Type
----------------------------------------- -------- ----------------------------
SID NOT NULL NUMBER(5)
SNAME VARCHAR2(15)
SDEPT VARCHAR2(10)
TOTAL NUMBER(5)

c) RENAME TABLE:
Syntax:
Rename table_name1 to table_name2;
Description:
To rename a table.
Query:
SQL>rename classa to classb;
Output:
Table renamed.
SQL> desc classb;
Name Null? Type
----------------------------------------- -------- ----------------------------
SID NOT NULL NUMBER(5)
SNAME VARCHAR2(15)
SDEPT VARCHAR2(10)
TOTAL NUMBER(5)
d) DROP TABLE QUERY:
Syntax:
Drop table<table name>
Description:
To delete the entire table.
Query:
Drop table classb;
Output:
Table dropped.

CONSTRAINT:
1.NOT NULL
SYNTAX:
Create table <tablename>(column_name1 datatypa(size),Column_name2 datatype(size),Coulumn_name3 datatyp(size)not
null);
DESCRIPTION:
To enforce the field or column always contain value.
QUERY:
create table bass(no number(5),name char(20)not null,mark number(5));
OUTPUT:
SQL> desc bass;
Name Null? Type
----------------------------------------- -------- ----------------------------
NO NUMBER(5)
NAME NOT NULL CHAR(20)
MARK NUMBER(5)

2.UNIQUE:
SYNTAX:
Create table <tablename>(column_name1 datatypa(size)unqiue,Column_name2 datatype(size),Coulumn_name3
datatyp(size)…);
DESCRIPTION:
The unqiue constraints is used to uniquely identifies each record in a database table.
QUERY:
SQL>create table xass(no number(10)unique,name char(20),mark number(10));
OUTPUT:
SQL> desc xass;
Name Null? Type
----------------------------------------- -------- ----------------------------
NO NUMBER(10)
NAME CHAR(20)
MARK NUMBER(10)
3.PRIMARY KEY:
SYNTAX:
Create table <tablename>(column_name1 datatypa(size)primary keyColumn_name2 datatype(size),Coulumn_name3
datatyp(size)…);
DESCRIPTION:
The primary key is used to identify the data uniquely and it is no null.
QUERY:
create table fds(no number(4)primary key,name char(20),mark number(10));
OUTPUT:
SQL> desc fds;
Name Null? Type
----------------------------------------- -------- ----------------------------
NO NOT NULL NUMBER(4)
NAME CHAR(20)
MARK NUMBER(10)

4.FOREIGN KEY:
SYNTAX:
Create table table_name2(column1 datatype(size),column2 datatype (size),constraint anyword foreign
key(column_name)references tablename1(column_name));
DESCRIPTION:
It is also called references key.A foreign key in one table points to a primary key by a another table.
QUERY:
create table gds(no number(5),name char(20),mark number(10), constraint fred foreign key(no)references fds(no));

OUTPUT:
SQL> desc gds;
Name Null? Type
----------------------------------------- -------- ----------------------------
NO NUMBER(5)
NAME CHAR(20)
MARK NUMBER(10)
5.CHECK CONSTRAINT
SYNTAX:
CREATE Table table_name(col1 datatype(size),col2 datatype(size),check (col1>=value));
DESCRIPTION:
The check constraint is used to limit a value range that can be placed in a column.
QUERY:
CREATE Table cass(no number(5),name char(20),age number(5),check (age>=18));

OUTPUT:
SQL> desc cass;

Name Null? Type


----------------------------------------- -------- ----------------------------
NO NUMBER(5)
NAME CHAR(20)
AGE NUMBER(5)

6.DEFAULT CONSTRAINT:
SYNTAX:
CREATE Table table_name(col1 datatype(size), col2 datatype(size),default value));
DESCRIPTION:
The default constraint is used to insert a default value into a column.

QUERY:
CREATE Table ytre(regno number(5),name char(10),age number default 18);
OUPUT:
SQL> desc ytre;
Name Null? Type
----------------------------------------- -------- ----------------------------
NO NUMBER(5)
NAME CHAR(20)
AGE NUMBER(5)
RESULT:

Thus the Data Definition Language commands (create, alter, drop) are studied and
executed successfully and output was verified.
Ex.No:1(b) DATA MANIPULATION LANGUAGE

AIM:
To execute and verify Data Manipulation Language commands (select, insert, update and delete).

1.INSERT:
(a) To insert one data:
Syntax:
Insert into table name [(column name…..n column name)] values (expression…);
Description:
Adding data to a database is accomplished by SQL insert statements.
Query:
insert into cust13 values('sairam',145,'kanchipuram',9000,’SBI’,'kanchipuram’') ;
Output:
1 row created
SQL> select * from cust13;
CNAME ACC ADDR BAL BNAME BCITY
---------- ---------- -------------------- ---------- ---------- ------------------
Sairam 145 kanchipuram 9000 SBI kanchipuram

(b) To insert more than one data:


Syntax:
Insert into table name [(column name…..n column name)] values (expression…);
Query:
SQL> insert into cust13 values('&cname','&acc','&addr','&bal','&bname','&bcity');
Enter value for cname: ezhil
Enter value for acc: 123
Enter value for addr: chennai
Enter value for bal: 6000
Enter value for bname: indian
Enter value for bcity: chennai
1 row created.
SQL> /
Enter value for cname: vino
Enter value for acc: 124
Enter value for addr: karur
Enter value for bal: 6000
Enter value for bname: state bank
Enter value for bcity: karur
1 row created.
SQL> select * from cust13;
CNAME ACC ADDR BAL BNAME BCITY
---------- ---------- -------------------- ---------- ---------- ---------------
ezhil 123 chennai 6000 indian chennai
vino 124 karur 6000 state bank karur
(b) UPDATE:
Syntax:
Update table name set column name=expression, column name=expression…where column
name=expression;
Description:
SQL provides the ability to modify existing data using update statements
Query:
SQL> update classa set total=400 where sid='5';
1 row updated.
SQL> select * from classa;
SID SNAME SDEPT TOTAL
---------- ---------- ---------- ---------------------
2 aarthi cse 600
3 sakthi it 500
4 vino ece 900
5 ezhil eee 400
6 kalpana it 300

c) DELETE:
Syntax:
Delete from table name where (condition);
Description:
Rows are removed from tables through the use of delete statement.The where clause is optional.
If it is not specified, all rows in selected table are removed.
Query:
SQL> delete from classa where sid='5';
1 row deleted.
SQL> select * from classa;
SID SNAME SDEPT TOTAL
---------- ---------- ---------- -------------------
2 aarthi cse 600
3 sakthi it 500
4 vino ece 900
6 kalpana it 300
d) SELECT:
Syntax:
Select * from table name [where conditions, group by column-list having conditions,
order by column-names];
Description:
Select query is used for data retrieval
Query: To retrieve tuples in a table using select query:
SQL> select * from classa;
SID SNAME SDEPT TOTAL
---------- ---------- ---------- ----------
2 aarthi cse 600
3 sakthi it 500
4 vino ece 900
6 kalpana it 300

Retriving specific columns:


SQL> select sid,sname from classa;
SID SNAME
---------- ----------
2 aarthi
3 sakthi
4 vino
5 ezhil
Eliminating duplicates:
SQL> select distinct sdept from classa;
SDEPT
----------
cse
ece
it
Specifying condition:
SQL> select sname from classa where total>400;
SNAME
----------
aarthi
sakthi
vino
Sorting record set:
SQL> select sname from classa order by sname asc;
SNAME
----------
aarthi
ezhil
kalpana
sakthi
vino
SQL> select sname,sdept from classa order by sname asc,sdept desc;
SNAME SDEPT
---------- ----------
aarthi cse
ezhil
kalpana it
sakthi it
vino ece
USING SQL SPECIAL OPERATOR:
(i) Rows with null values:
SQL> select * from classa where sdept is null;
SID SNAME SDEPT TOTAL
--------- ---------- ---------- ----------
5 ezhil
(ii) Between operator
SQL> select * from classa where total between 500 and 1000;
SID SNAME SDEPT TOTAL
---------- ---------- ---------- ----------
2 aarthi cse 600
3 sakthi it 500
4 vino ece 900
(iii) In operator:
SQL> select * from classa where sdept in('it');
SID SNAME SDEPT TOTAL
---------- ---------- ---------- ----------
3 sakthi it 500
6 kalpana it 300
(iv) Like operator
(i) SQL> select * from classa where sname like 's%';
SID SNAME SDEPT TOTAL
---------- ---------- ---------- ----------
3 sakthi it 500
(ii) SQL> select * from classa where sname like '_a%';
SID SNAME SDEPT TOTAL
---------- ---------- ---------- ----------
2 aarthi cse 600
3 sakthi it 500
6 kalpana it 300

RESULT:

Thus the Data Manipulation Language commands(insert, update, delete) are studied
and executed successfully and output was verified.
Ex.No:1(c) TRANSACTION CONTROL STATEMENTS

AIM:
To execute the various transaction control statements.

COMMIT :
Syntax:
Commit;
Description:
It is used to permanently save any transaction into database.
Query:
SQL> select * from class;
NAME ID
---------- ----------
anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
SQL> insert into class values('gayathri',9);
1 row created.
SQL> commit;
Commit complete.
SAVEPOINT:
Syntax:
Savepoint savapoint_name;
Description:
It is used to temporarily save a transaction so that you can rollback to that point whenever necessary.
Query:
SQL> update class set name='hema' where id='9';
1 row updated.
SQL> savepoint A;
Savepoint created.
SQL> insert into class values('indu',11); 1 row
created.
SQL> savepoint B;
Savepoint created.
SQL> insert into class values('janani',13);
1 row created.
SQL> select * from class;
NAME ID
---------- --------------------
anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
indu 11
janani 13
9 rows selected.
ROLLBACK:
Syntax:
Rollback to savepoint_name;
Description:
It restores the database to last commited state. It is also use with savepoint command to jump to a
savepoint in a transaction
Query:
SQL> rollback toB; Rollback
complete.
SQL> select * from class;
NAME ID
---------- ----------

anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
indu 11
8 rows selected. SQL> rollback to
A; Rollback complete.
SQL> select * from class;
NAME ID
---------- ----------

anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
RESULT:

Thus the Transaction control statements commands(commit,rollback,savepoint) are studied


and executed successfully and output was verified.
Ex.No:2(a) SIMPLE QUERIES

AIM:
To implement and execute the simple queries in oracle database.
1.GROUP BY:
SYNTAX:
select column_name aggregate _function(column name)from table_name where column_name operator value GROUP BY
column_name;
DESCRIPTION:
The group by statement is used in conjuction with the aggregate functions to group the result set by one or more columns.
QUERY
SQL> select mark,min(name) from row123 group by mark;
OUTPUT:
MARK MIN(NAME)
---------- -------------------
23 allia
80 zeen
90 gopi
2.HAVING:
SYNTAX:
select column_name,aggregate_function(column_name)from
tablename GROUP BY column_name HAVING aggregate_function(column_name)> condition;
DESCRIPTION:
It is used to filter data based on group functions. This is similar ‘where condition that Is used with group functions’.
QUERY:
select regno,avg(mark) from row123 group by regno having avg(mark)<90 ;
OUTPUT:
REGNO AVG(MARK)
------ ----------
12 80
21 23

3.ORDER BY:
SYNTAX:
for ascending order:
select * from tablename ORDER BY column_name asc;
for descending order:
select * from tablename ORDER BY column_name desc;
DESCRIPTION:
The order by clause tuples in the result of a query to n appear in sorted order.The order by clause arranges in ascending
or descending order.
QUERY :
(i)for ascending order:
SQL> select * from row123 order by mark asc;
OUTPUT:
NAME MARK DEPT REGNO
---------- ---------- ---------- ----------
allia 23 ece 21
zeen 80 cse 12
gopi 90 mech 10
(ii)for descending order:
SQL> select * from row123 ORDER BY mark desc;
OUTPUT:
NAME MARK DEPT REGNO
---------- ---------- ---------- --------
gopi 90 mech 10
zeen 80 cse 12
allia 23 ece 21

RESULT:

Thus the simple queries command are studied and executed successfully and output was verified.
Ex.No:2(b) JOIN QUERIES

AIM:
To create a database using join query.
1.INNER JOIN :
SYANTAX:
Select reference object 1.column name 1,,column name 2,,column name3 From table name 1 reference
object1 Inner join table name 2referenceobject 2On reference object 1.column name =reference object
2.column name;
DESCRIPTION
:To return rows where there is atleast one match in both table.
QUERY:
selecta.idno,prono,orderno,uname from userdda inner join orderlistdd b on a.idno=b.idno;
OUTPUT:
IDNO PRONO ORDERNO UNAME
---------- ---------- ---------- ---------------------------- -
1 90 89 haritha
2 78 45 uki

2.LEFT JOIN:
SYNTAX:
Select reference object 1.column name 1, ,column name 2, ,column name3 From table name 1
reference object 1
left join table name 2 reference object 2 On reference object 1.column name = reference object
2.column name;
DESCRIPTION:
To return all rows from the left table even if there are no match in the right table
QUERY:
selecta.idno,prono,orderno,uname from userdd a left join orderlistdd b on a.idno=b.idno;
OUTPUT:
IDNO PRONO ORDERNO UNAME
---------- ---------- ---------- ----------------------------------
1 90 89 haritha
2 78 45 uki
4 52 42 uj
3 56 23 koko

3.RIGHT JOIN:
SYNTAX:
Select reference object 1.column name 1, ,column name 2, ,column name3 From table name 1
reference object 1
right join table name 2 reference object 2 On reference object 1.column name = reference object
2.column name;
DESCRIPTION:
To return all rows from the right table even if there are no match in the left table
QUERY
:selecta.idno,prono,orderno,uname from userdd a right join orderlistdd b on a.idno=b.idno;
OUTPUT:
IDNO PRONO ORDERNO UNAME
---------- ---------- ---------- ------------------------------
1 90 89 haritha
2 78 45 uki

4.EQUIJOIN:
SYNTAX:
select *from table1 equi join table2 on table1.col_name=table2.col_name;
DESCRIPTION:
It is used to display all the matched records from both table and also displays redundant values.
QUERY
select a.idno,prono,orderno,uname from userdd a equi join orderlistdd b on a.idno=b.idno;
OUTPUT:
IDNO UNAME FNAME LNAME IDNO ORDERNO PRONO
---------------------------------------------------------------------------------------------------------------
1 harithaharitha 1 89 90 52
2 uki u ki 2 45 78

5.NATURAL JOIN:
SYNTAX:
Select *from table1 natural join table2;
DESCRIPTION:
It is used to display all the matched records from both tables and it avoids the redundant values.
QUERY
select *from userdd natural join orderlistdd;
OUTPUT:
IDNO UNAME FNAME LNAME ORDERNO PRONO
----------- -------------- ----------------- -------------- ------------------- -------------------=
1 haritha haritha 89 90 52

2 ukiu ki 45 78 85

6.CROSS JOIN:
SYNTAX:
Select *from table1 cross join table2;
DESCRIPTION:
It produces Cartesian product of the table. The size of the Cartesian product is the number of the rows
in the first table multiplied by the number of rows in the second table.
QUERY:
select *from userdd cross join orderlistdd;
Output:
IDNO UNAME FNAME LNAME IDNO ORDERNO PRONO
------------- ------------------ ------------------ --------------- ------------ ----------------- ----------------
1 haritha haritha 1 89 90

2 ukiu ki1 89 90

3 koko koko1 89 90

7.OUTER JOIN:
(a)LEFT OUTER JOIN:
SYNTAX:
Select table1.col_name(s) from table1 left outer join table2 on table1.col_name=table2.col_name;
DESCRIPTION:
QUERY:
select a.idno,a.uname,a.fname,prono,orderno from userdd a left outer join orderlistdd b on
a.idno=b.idno;
OUTPUT:
IDNO UNAME FNAME PRONO ORDERNO
----------- ------------------ -------------------- ------------------ --------------------
1 harithahari 90 89
2 ukiu 78 45
4 uju
3 kokoko

(b)RIGHT OUTER JOIN:


SYNTAX:
Select table1.col_name(s) from table1 right outer join table2 on table1.col_name=table2.col_name;
DESCRIPTION:
It is used to display all the records from the second table and match rows from the first table.
QUERY:
select a.idno,a.uname,a.fname,prono,orderno from userdd a right outer join orderlistdd b on
a.idno=b.idno;
OUTPUT:
IDNO UNAME FNAME PRONO ORDERNO
------------ --------------- ------------------ ----------------- ----------------
1 haritha hari 90 89
2 uki u 78 45
100 68
99 67
(c)FULL OUTER JOIN:
SYNTAX:
Select table1.col_name(s) from table1 full outer join table2 on table1.col_name=table2.col_name;
DESCRIPTION:
It is used to display all the matching and non-matching rows of both the tables.
QUERY:
select a.idno,a.uname,a.fname,prono,orderno from userdd a full outer join orderlistdd b on a.id;
OUTPUT:
IDNO UNAME FNAME PRONO ORDERNO
---------- ---------------- ---------------- ---------------- -------------------
1 haritha hari 90 89
2 uki u 78 45
4 uju oop 85 89
3 kokoko plk 45 96

RESULT:
Thus the various join queries were executed and verified successfully.
Ex.No:2(C) NESTED QUERIES

AIM:
To execute various nested quories.
1.CREATE A TABLE:
SYNTAX:
Create table table_name2 as select*from table_name1;
DESCRIPTION:t
o create a new table as like the table that already exist.
QUERY:
SQL>descneha;
Name Null? Type
-------------------------------------------------------------------------------------------
SnoNumber
RegnoNumber
Name Varchar(2)
SQL>create table anosha as select *from neha;
OUTPUT:
Table created.
SQL>descanosha;
Name Null? Type
-------------------------------------------------------------------------------------
Sno Number
Regno Number
Name Varchar(2)

2.INSERTING VALUES:
SYNTAX:
insert into table_name2 select *from table_name1;
DESCRIPTION:
to insert the values from one table to another table.
QUERY:
select *from neha;
SNO REGNO NAME

1 4001 aarthi
2 4002 abirami
SQL> insert into anosha select *from nesha;
OUTPUT:
2 rows selected.
SQL>select *from sri;

SNO REGNO NAME


1 4001 aarthi
2 4002 abirami

3.DISPLAYING THE CONTENTS:


SYNAX:
Select column_name from table_name2 where column_name in(select column_name from
table_name1);
DESCRIPTION:
to display the contents of a table by comparing two tables.
QUERY:
SQL>select *from stud; SQL>select *from student;
SNO REGNO NAME SNO ADDRESS CITY
------------------------------------------ ----------------------------------------------------------
1 1001 abi 1 Gandhi nagartirpur
2 1002 karan 3 raja nagar chennai
3 1003 anu 4 gieinagar Coimbatore
SQL>select name from stud where sno in (select sno from student);
OUTPUT:
NAME
----------------
Abi
Karan

RESULT:
Thus the various nested queries were executed and verified successfully.
Ex.No:3 VIEWS,SEQUENCES AND SYNONYMS

AIM
To execute and verify the SQL commands for Views, Sequences and Synonyms

VIEWS:
Syntax:
Create view v as <query expression>
Description:
SQL includes the ability to create stored queries that they can then be used as a basis for other
queries. These stored queries are also called views. A view is simply a derived table that is built upon
the base tables of the database. Base tables are the original database tables that actually contain data.
Views do not actually store data they are temporary tables. To define a view, we must give the view a
name and state the query that computes the view.
Query:
SQL>create view classa_b as select classa.sid, classa.sname, classa.sdept, classb.grade from classa,
classb where classa.sid=classb.id order by classa.sid;
Output:
View created
SQL> select * from classa_b;
SID SNAME SDEPT GRADE
---------- --------------- ---------- ----------
1 aarthi IT b
2 ezhil ECE b
6 sumathi ECE a
7 viji IT a
SQL> select sid, sname, sdept from classa_b where sdept='IT';
SID SNAME SDEPT
---------- -------------- ----------
1 aarthi IT
7 viji IT
RENAMING COLUMNS IN A VIEW:
Another useful feature available when creating a view is that columns can be renamed in the
CREATE VIEW statement. The new column names only apply to the views, the column names in the
base tables do not change.
Query:
SQL> create view classxy12(id,dept) as select sid,sdept from classa;
View created.
SQL> select * from classxy12;
ID DEPT
---------- ----------
1 IT
2 ECE
3 IT
4 ECE
5 IT
6 ECE

6 rows selected.
USING AGGREGATION FUNCTIONS WITH VIEWS:
Aggregate function that take a collection of value as input and return a single value .SQL offers
five built in aggregate function such as count, sum ,average, minimum and maximum.Count function
will count all the rows including duplicates or null. Sum function calculates the sum of all values in
specified column. The average function produces arithmetic mean of all the selected values or fields.
The maximum function produces max values of all the selected values of a given fields. The minimum
function produces min values of all the selected values of a given fields.
Query:
SQL> create table course1(section varchar2(10),course varchar2(10),studentname varchar2(10),total
varchar2(10));
Table created.
SQL> select * from course1;
SECTION COURSE STUDENTNAM TOTAL
------------------ ---------- ------------------------ ----------
121 IT vino 500
121 IT ezhil 450
122 ECE sakthi 345
122 ECE aarthi 450
SQL>create view student_count_min(sno,count) as select min(section),count(studentname) from
course1;
View created.
SQL> select *from student_count_min;
SNO COUNT
---------- ----------
121 4
SQL> create view student_sum_avg(tot,avgtotal)as select sum(total),avg(total) from course1;
View created.
SQL> select * from student_sum_avg;
TOT AVGTOTAL
---------- ----------
1745 436.25
SQL> create view stud_max(tot) as select max(total) from course1;
View created.
SQL> select * from stud_max;
TOT
----------
500
QUERIES COMBINING VIEWS AND TABLES:

Queries can combine information from a view and a table by listing the view and the table in the
FROM clause. These queries usea join condition, just as in a multi-table query, except the join
condition will match a column in the view with a column in the table.
Query:
SQL> select * from classa;
SID SNAME SDEPT TOTAL
---------- --------------- ---------------------- ----------
2 ezhil ECE 590
6 sumathi ECE 890
SQL> select * from classa_b;
SID SNAME SDEPT GRADE
------------- --------- ----------------- ----------
2 ezhil ECE b
SQL> select classa.sid,classa.sname,classa.sdept,classa.total,classa_b.grade from classa, classa_b
where classa.sid=classa_b.sid;
SID SNAME SDEPT TOTAL GRADE
---------- -------------------------- ---------- --------------- --------------
2 ezhil ECE 590 b
DATA MANIPULATION IN VIEWS:
SQL provides the ability to modify existing data using update statements. Rows are
removed from tables through the use of delete statement. Adding data to a database is
accomplished by SQL insert statements. Select query is used for data retrieval.
Query:
SQL> Insert into classxy12 values ('8','ECE');
1 row created.
SQL> select * from classxy12;
ID DEPT
---------- ----------
1 IT
2 ECE
3 IT
4 ECE
7 IT
6 ECE
8 ECE
7 rows selected.
SQL> delete from classxy12 where dept='IT';
3 rows deleted.
SQL> select * from classXY12;
ID DEPT
---------- ----------
2 ECE
4 ECE
6 ECE
8 ECE
SQL> update classxy12 set dept='IT' where id='4';
1 row updated.

SQL> select * from classxy12;


ID DEPT
---------- ----------
2 ECE
4 IT
6 ECE
8 ECE
SQL> select * from classa;
SID SNAME SDEPT TOTAL
---------- --------------- ---------- -----------------------
2 ezhil ECE 590
6 sumathi ECE 890
SQL> select * from classb;
ID NAME GRADE
---------- ---------- ----------
1 aarthi b
2 ezhil b
NATURAL INNER JOIN IN VIEWS:
SQL uses the keyword join in the form clause to specify equi joins. The output of Select common
name from table1 natural inner join table 2;Consist of the attributes of table, followed by attributes of
table 2. The tuples in the result query would be all the tuples which have equal value on the common
attributes.
Query:
SQL> create view classab12 as select * from (classa natural inner join classb);
View created.
SQL> select * from classab12;
SID SNAME SDEPT TOTAL ID NAME GRADE
-------------------- --------------- ---------- ---------- ---------- ----------
2 ezhil ECE 590 1 aarthi b
6 sumathi ECE 890 1 aarthi b
2 ezhil ECE 590 2 ezhil b
6 sumathi ECE 890 2 ezhil b

SEQUENCE:
Sequence is a feature supported by some database systems to produce unique values on demand.
Some DBMS like MySQL supports AUTO_INCREMENT in place of sequence. AUTO_INCREMENT
is applied on columns. It automatically increments the column value by 1 each time a new record is
entered into the table. Sequence is also some what similar to AUTO_INCREMENT but its has some
extra features.
Query:
SQL> select * from class;

NAME ID
---------- ----------------------

anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9

7 rows selected.
Create synonym:
SQL> create synonym c1 for class;
Synonym created.
SQL> insert into c1 values('kalai',20);
1 row created.
SQL> select * from class;
NAME ID
-------------- -------------

anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20
8rows selected.
SQL> select * from c1;

NAME ID
---------- ----------

anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20

8 rows selected.

SQL> insert into class values('Manu',21); 1 row created.


SQL> select * from c1;
NAME ID
----------- ---------------

anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20
Manu 21

9 rows selected.
Drop Synonym:
SQL> drop synonym c1; Synonym
dropped.
SQL> select * from c1; select * from c1
* ERROR at line 1:
ORA-00942: table or view does not
xist
SEQUENCES
Oracle provides the capability to generate sequences of unique numbers, and they are
called sequences. Just like tables, views, indexes, and synonyms, a sequence is a type of database
object. Sequences are used to generate unique, sequential integer values that are used as primary key
values in database tables. The sequence of numbers can be generated in either ascending or descending
order.
Query:
Creation of table:
SQL> create table class(name varchar(10),id number(10)); Table created.
Insert values into table:
SQL> insert into class values('&name',&id); Enter value for
name: anu
Enter value for id: 1
old 1: insert into class values('&name',&id)
new 1: insert into classvalues('anu',1)
1 row created.
SQL> /
Enter value for name: brindha
Enter value for id: 02
old 1: insert into class values('&name',&id)
new 1: insert into class values('brindha',02)
1 row created.
SQL> /
Enter value for name: chinthiya
Enter value for id: 03
old 1: insert into class values('&name',&id)
new 1: insert into class values('chinthiya',03)
1 row created.
SQL> select * from class;

NAME ID
--------- ----------
Anu 1
Brindha 2
Chinthiya 3

Create Sequence:
SQL> create sequence s_1
2 start with 4
3 increment by 1
4 maxvalue 100
5 cycle;
Sequence created.
SQL> insert into class values('divya',s_1.nextval); 1 row created.
SQL> select * from class;
NAME ID
---------- ----------

anu 1
brindha 2
chinthiya 3
divya 4
Alter Sequence:
SQL> alter sequence s_1
2 increment by 2;
Sequence altered.
SQL> insert into class values('fairoz',s_1.nextval); 1 row created.
SQL> select * from class;
NAME ID
---------- ----------

anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
Drop Sequence:
SQL> drop sequence s_1;
Sequence dropped.

RESULT:
Thus the SQL commands for View, sequence and synonyms has been executed successfully and output
was verified.
Ex.No:4(a) IMPLICIT CURSORS

AIM:
To write a PL/SQL code block to implicit cursors.
ALGORITHM:
STEP-1: Start
STEP-2: Go to SQL.
STEP-3: Enter the username and password.
STEP-4: Type the program and compile it.
STEP-5: The output is verified.
STEP-6: Stop
PROGRAM:

Begin
Update emp_information SET emp_dept=’web developer’
Where emp_name=’saulin’;
IF SQL%FOUND THEN
Dbms_output.put_line(‘UPDATE – IF FOUND’);
END IF
IF SQL%NOTFOUND THEN
Dbms_output.put_line(‘NOT UPDATE – IF NOT FOUND’);
END IF
IF SQL%ROWCOUNT > 0 THEN
Dbms_output.put_line(‘SQL%ROWCOUNT||’ROWS UPDATED’);
ELSE
Dbms_output.put_line(‘NO ROW UPDATE FOUND’);
END;
/
OUTPUT:
UPDATE – IF FOUND
1 ROW UPDATED
PL/SQL PROCEDURE SUCCESSFULLY COMPLETED.

RESULT:
Thus the PL/SQL program for implicit cursor was verified successfully.
Ex.No:4(b) EXPLICIT CURSOR

AIM:

To write the PL/SQL program to explicit cursor.

ALGORITHM:

STEP-1: start
STEP-2: declare the cursor creation used in the program
STEP-3: under the begin section in open a cursor and fetch a rows
STEP-4:end loop
STEP-5: display a output and close a cursor
STEP-6: stop.
PROGRAM:

Declare
Cursor er IS select eid, name from emp orderby name;
Id emp.eid%type;
Ename emp.name%type;
Begin
OPEN er;
LOOP
FETCH er into id,ename;
EXIT when er%notfound;
Dbms_output.put_line(id||ename);
End loop
Close er;
END;
/
OUTPUT:

1 || parimal
2 || preet
PL/SQL procedurce successfully completed.

RESULT:
Thus the PL/SQL program for implicit cursor was verified successfully.
Ex.No:5(a) FIBONACCI SERIES

AIM:
To write a PL/SQL code block program to generate the Fibonacci Series
ALGORITHM:
STEP-1: Start the program.
STEP-2: Declare the variables.
STEP-3: Initialize a=0 and b=1
STEP-4:Get the value of n
STEP-5: Incrementing the value of iupto n in loop.
STEP-6: Display the value of a result.
STEP-7: stop the program.
PROGRAM:
declare
a number(10);
b number(10);
c number(10);
n number(10);
i number(10);
begin
a:=0;
b:=1;
i:=0;
n:=&n;
dbms_output.put_line(a);
dbms_output.put_line(b);
while(n-2>i)
loop
c:=a+b;
dbms_output.put_line(c);
a:=b;
b:=c;
i:=i+1;
end loop;
end;

OUTPUT:
SQL> /
Enter value for n: 5
old 11: n:=&n;
new 11: n:=5;
0
1
1
2
3
PL/SQL procedure successfully completed.
RESULT:
Thus the PL/SQL for generating the Fibonacci series was verified successfully.
Ex.No:5(b) PALINDROME

AIM:
To Write a procedure for Palindrome of the given String.
ALGORITHM:

STEP-1: start
STEP-2: declare the variables used in the program
STEP-3: under the begin section in for loop check the palindrome
STEP-4:end loop
STEP-5: display the output by using the output syntax
STEP-6: stop.
PROGRAM:
declare
g varchar2(20);
r varchar2(20);
begin
g:='&g';dbms_output.put_line('the given text='||g);
for i in reverse 1..length(g)loop
r:=r||substr(g,i,1);
end loop;
dbms_output.put_line('the reserved text:'||r);
if r=g then
dbms_output.put_line('the given text is palindrome');
else
dbms_output.put_line('the given text is not palindrome');
end if;
end;
/
OUTPUT:
SQL> @pal;
Enter value for g: madam
old 5: g:='&g';dbms_output.put_line('the given text='||g);
new 5: g:='madam';dbms_output.put_line('the given text='||g);
the given text=madam
the reserved text:madam
the given text is palindrome

PL/SQL procedure successfully completed.


Result:
Thus the PL/SQL for Palindrome of the given String was verified successfully.
Ex.No:5(c) STUDENT DATABASE

AIM:
To write a procedure for Student Database.

ALGORITHM:
STEP-1: Start the program.
STEP-2: Declare the variables.
STEP-3: Initialize a=0 and b=1.
STEP-4: calculate the total of studented
STEP-5: Display the value of a total, avg, result.
STEP-6: Stop the program.

SQL> select * from studs;


NAME ROLLNO MARK1 MARK2 MARK3 TOTAL AVG RESULT
------------ ---------- ---------- ---------- ---------- ---------- ------ -----------
nisha 45 98 97 96
dhana 46 99 98 88
sharmi 47 89 93 81
hema 48 94 87 45
selvi 49 35 65 41
mani 50 41 65 78
sam 51 63 87 72

7 rows selected.
PROGRAM:

SQL> declare
2 s studs%rowtype;
3 a number(5);
4 begin
5 a:=45;
6 while(a<=51)
7 loop
8 select mark1,mark2,mark3 into s.mark1,s.mark2,s.mark3 from studs where rollno=a;
9 if(s.mark1>=50 and s.mark2>=50 and s.mark3>=50)then
10 s.result:='pass';
11 else
12 s.result:='fail';
13 end if;
14 s.total:=s.mark1+s.mark2+s.mark3;
15 s.avg:=s.total/3;
16 update studs set total=s.total where rollno=a;
17 update studs set avg=s.avg where rollno=a;
18 update studs set result=s.result where rollno=a;
19 a:=a+1;
20 end loop;
21 end;
22 /

PL/SQL procedure successfully completed.

OUTPUT:
SQL> select * from studs;
NAME ROLLNO MARK1 MARK2 MARK3 TOTAL AVG RESULT
------------ ---------- ---------- ---------- ---------- ---------- ------ -----------
nisha 45 98 97 96 291 97 pass
dhana 46 99 98 88 285 95 pass
sharmi 47 89 93 81 263 88 pass
hema 48 94 87 45 226 75 fail
selvi 49 35 65 41 141 47 fail
mani 50 41 65 78 184 61 fail
sam 51 63 87 72 222 74 pass

7 rows selected.
Result:

Thus the PL/SQL for students database was verified successfully.


Ex.No:5(d) SUM OF N NUMBERS

AIM:
To write a PL/SQL code block program to create functions for finding sum of n numbers.
ALGORITHM:
STEP-1: Start the program.
STEP-2: Declare the variables.
STEP-3: Initialize a=0 and b=1.
STEP-4: Get the values of a and b by incrementing value of bupto c and in c.
STEP-5: Display the value of a result.
STEP-6: Stop the program.
PROGRAM:
1 declare
2 a number(5):=0;
3 b number(5);
4 c number(5);
5 begin
6 c:='&c';
7 for b in 1..c loop
8 a:=a+b;
9 end loop;
10 dbms_output.put_line(‘sum of n numbers =’||a);
11* end;
SQL> /

OUTPUT:

Enter value for c: 3


old 6: c:='&c';
new 6: c:='6';
sum of n numbers =6

PL/SQL procedure successfully completed.


RESULT:
Thus the PL/SQL program for sum of n numbers was verified successfully.
Ex.No:5(e) FACTORIAL

AIM:
To write the PL/SQL program to find the factorial of a number.

ALGORITHM:

STEP-1: start
STEP-2: declare the variables used in program
STEP-3: under the begin section assume i=1 and j upto the given number
STEP-4: end loop
STEP-5: display the output by using the output format
STEP-6: stop
PROGRAM:
SQL> set serveroutput on
SQL> declare
2 i number(5);
3 j number (5);
4 f number(10);
5 begin
6 i:=&i;
7 f:=1;
8 for j in 1..i
9 loop
10 f:=f*j;
11 end loop;
12 dbms_output.put_line(f);
13 end;
14 .
SQL> /

OUTPUT:

Enter value for i: 3


old 6: i:=&i;
new 6: i:=3;
6

PL/SQL procedure successfully completed.

Enter value for i: 5


old 6: i:=&i;
new 6: i:=5;
120
RESULT:
Thus the PL/SQL for finding the factorial of a number was verified successfully.
Ex.No:5(f) AREA OF A CIRCLE

AIM:

To the write the PL/SQL program to find the area of a circle.

ALGORITHM:

STEP-1: start
STEP-2: declare the variable used in the program under the declare section
STEP-3: begin the program by assuming the radius to 1
STEP-4: under the while loop declare area as pi*pow(radius,2);
STEP-5: end loop
STEP-6: stop

PROGRAM:
SQL> set serveroutput on
SQL> declare
pi constant number(4,2):=3.14;
radius number(2);
area number(4,2);
begin
radius:=1;
while radius<=5
loop
area:=pi*power(radius,2);
insert into cirarea values(radius,area);
radius:=radius+1;
end loop;
end;
/

OUTPUT
PL/SQL procedure successfully completed.
SQL> select * from cirarea;
RADIUS AREA
---------------------------
3.14
12.56
28.26
50.24
78.5
RESULT:
Thus the PL/SQL for finding the area of circle was verified successfully
Ex.No:5(g) BIGGEST OF THREE NUMBER

AIM:

To write the PL/SQL program to find the biggest of three number

ALGORITHM:

STEP-1: start
STEP 2: under the declare section declare the variables used in program
STEP-3: in begin section get the values of variables
STEP-4: check the number with given condition
STEP-5: end if
STEP-6: stop.

PROGRAM:
declare
a number;
b number;
c number;
begin
a:=&a;
b:=&b;
c:=&c;
if a=b and b=c and c=a then
dbms_output.put_line('ALL ARE EQUAL');
elsif a>b and a>c then
dbms_output.put_line('A IS GREATER');
elsif b>c then
dbms_output.put_line('B IS GREATER');
else
dbms_output.put_line('C IS GREATER');
end if;
end;
/

OUTPUT:
SQL> @ GREATESTOF3.sql
Enter value for a: 8
old 6: a:=&a;
new 6: a:=8;
Enter value for b: 9
old 7: b:=&b;
new 7: b:=9;
Enter value for c: 7
old 8: c:=&c;
new 8: c:=7;
B IS GREATER
PL/SQL procedure successfully completed.
RESULT:
Thus the PL/SQL for finding the biggest of a number was verified successfully.
Ex.No:6 FUNCTION

AIM:
To execute the functions in SQL.

(1)NUMBER FUNCTIONS:
(a)CEIL:
SYNTAX:
select ceil(value) “heading” from dual;
DESCRIPTION:
This function is used to round off the number to the nearest value.
QUERY:
SQL> select ceil(15.7) ‘ceiling’ from dual;
OUTPUT:
Ceiling
------------
16

(b) FLOOR:
SYNTAX:
select floor(value) “heading” from dual;
DESCRIPTION:
This function will return the value leaving the numbers after the decimal point
QUERY:
SQL>select floor (15.7) “Floor” from dual;
OUTPUT:
Floor
-----------
15
(c) MOD:
SYNTAX:
select mod (value1,value2) “heading” from dual;
DESCRIPTION:
This function will perform the modulo(%) operation of the given two numbers.
QUERY:
SQL>select mod(26,11) “modulo” from dual;
OUTPUT:
Modulo
----------
4
(d)ROUND:
SYNTAX:
select round(value,limit) from dual;
DESCRIPTION:
This function will round of the value after the decimal point.
QUERY:
SQL>select round(54.339,2) “Round” from dual;
OUTPUT:
Round
-----------
54.34
(e)TRUNCATE:
SYNTAX:
Select trunc(decimal_value) from dual;
DESCRIPTION:
This function will display the number before the decimal point.
QUERY:
Select trunc(54.339) “truncate” from dual;
OUTPUT:
Truncate
------------
54

(2)CHARACTER FUNCTIONS:
(a)CHR:
SYNTAX:
Select chr(value) “heding” from dual;
DESCRIPTION:
This function will return the corresponding alphabet for the given ASCII value.
QUERY:
SQL>select chr(68)||chr(79)||chr(71) “god” from dual;
OUTPUT:
God
-------
GOD
(b)CONTACT:
SYNTAX:
Select concat(‘char1’, ‘char2’) from dual;
DESCRIPTION:
To join separate words together and display the single word obtained.
QUERY:
SQL>select concat(‘myth’, ‘ri’) “concat” from the dual;
OUTPUT:
Conca
---------
Mythri
(c)INITCAP:
SYNTAX:
Select initcap(‘sentence’) “heading” from dual;
DESCRIPTION:
This function will return the character with the first letter of each word in uppercase and all the other letters in lowercase.
QUERY:
SQL>select initcap(‘the box’) “capitals” from dual;
OUTPUT:
Capitals
------------
The box
(d)LOWER:
SYNTAX:
select lower(‘word’) “heading” from dual;
DESCRIPTION:
This function will return all the characters in the sequence in lowercase
QUERY:
SQL>select lower(‘temple’) “lower” from dual;
OUTPUT:
Lower
-----------
Temple

(e)PADDING:

 LPAD:
SYNTAX:
Select lpad (‘word’,number,‘symbol’) “heading” from dual;
DESCRIPTION:
This function will pad the given character or symbol to the leftside of the given word.
QUERY:
SQL>select lpad(‘page1’,15, ‘*.’) “LPAD example” from dual;
OUTPUT:
LPAD example
-------------
*.*.*.*.*.page1

 RPAD:
SYNTAX:
Select rpad(‘char1’,number, ‘char2’) “heading” from dual;
DESCRIPTION:
This function will pad the given character or symbol to the rightside of the given word.
OUTPUT:
RPAD example
-------------
page1*.*.*.*.*.
(f)LTRIM:
SYNTAX:
Select ltrim(‘char1’, ‘set’) “heading” from dual;
DESCRIPTION:
This function will remove the characters from the left of the characters that appear in the set remod;
QUERY:
SQL>select ltrim(‘xyxyxyLAST WORD’, ‘xy’) “LTRIM example” FROM DUAL;
OUTPUT:
LTRIM example
------------
LAST WORD
(g)REPLACE:
SYNTAX:
select replace (‘char’, ‘search string’, ‘replace string’) “heading” FROM DUAL;
DESCRIPTION:
This function will return the characters with every occurance of search string the replaced with the replacement string
QUERY:
SQL>select replace (‘jack and jue’, ‘j’, ‘bl’) “changes” FROM DUAL;
OUTPUT:
Changes
------------
Black and blue
(h)SUBSTR:
SYNTAX:
Select substr(‘char’,m,n) “heading FROM DUAL:
SQL>select substr(,’information’,3,4) from dual;
OUTPUT:
Subs
---------
Form
(i)TRANSLATE:
SYNTAX:
select translate(‘char’, ‘from’, ‘to’) from dual;
DESCRIPTION:
This function will translate the letter from one form to another
QUERY:
SQL>select translate(‘element’, ‘m’,5) from dual;
OUTPUT:
Element
(j)USER:
SYNTAX:
select user “heading” from dual;
DESCRIPTION:
This function will display the current user.
QUERY:
SQL>select user “user” from dual;
OUTPUT:
USER
----------
SCOTT

RESULT:
Thus the functions in SQL was executed and verified successfully.
Ex.No:7 TRIGGERS

AIM:
To execute and verify the before insert trigger , after insert trigger,before delete trigger,after delete trigger with
syntax and example.

1.BEFORE INSERT:
SQL>CREATE TRIGGER vs
2 BEFORE INSERT
3 on ordersll
4 or each row
5 declare
6 v_usernamevarchar2(10);
7 begin
8 select user into v_username from dual;
9 new.create_date:=sysdate;
10 new.created_by:=v_username;
11 end;
Trigger created.

OUTPUT:
SQL> insert into ordersllvalues(1002,20,25,500,'01-april-2014','lak');
insert into ordersll values(1002,20,25,500,'01-april-2014','lak')
*
ERROR at line 1:
ORA-04098: trigger 'SCOTT.LAL' is invalid and failed re-validation
2.AFTER INSERT:
SQL>create trigger kkk
1 after insert on salary
2 declare
3 k integer;
4 begin
5 select count(*) into k from salaryla;
6 if(k>=10) then
7 dbms_output.put_line('add only 2');
8 end if;
9 end;
Trigger created.

OUTPUT:
SQL> insert into salarylavalues(1001,'sara',5000) ;
1 row created.
SQL> select *from salaryla;
ENO ENAME AMOUNT
--------------------------------------------------
1001 sara 5000
3.AFTER DELETE:
SQL>create trigger juju
1 after delete on salaryla
2 for each row
3 begin
4 dbms_output.put_line('deletion is done');
5 end;

Trigger created.

OUTPUT:
SQL> delete from salaryla where eno=1;
0 rows deleted.
4.BEFORE DELETE:
SQL>Create trigger delmsg
1 Before delete on salary
2 For each row
3 Begin
4 Raise_application_error(-23099,’detail record may be present’);
5 End;

Trigger created.

OUTPUT:
Sql>delete from salary;
Delete from sal
*
Error at line 1;
Error during execution of trigger
‘241752’ del msg.
5.BEFORE UPDATE:
SQL>Create trigger updatetri
1 Begin
2 Raise_application_error(-2033,’no more deduction’);
3 End;
Trigger created.

OUTPUT:
Update set salary name=’I’;
Error:error during execution of trigger.

RESULT:
Thus the PL/SQL program to illustrate triggers are executed and the output is verified.
Ex.No: 8(a) USER DEFINE EXCEPTION HANDLING

AIM:
To write a PL/SQL program to user define exception handling.

PROGRAM:

SQL>declare
2 n integer:=&n
3 a exception;
4 b exception;
5 begin
6 if mod(n,2)=0 then
7 raise a;
8 else
9 raise b;
10 end if;
11 exception
12 when a then
13 dbms_output.put_line(‘the input is even…….’)
14 when b then
15 dbms_output.put_line(‘the input is odd…….’)
16 end;
17/
OUTPUT:
Enter value for n: 20
Old 2: n integer:=&n;
New 2: n integer:=20;
The input is even
PL/SQL procedure successfully completed.
SQL>/
Enter value for n: 21
Old 2: n integer:=&n;
New 2: n integer:=21;
The input is odd
PL/SQL procedure successfully completed.

RESULT:
Thus the PL/SQL program for exception handling was written , executed and the output was verified successfully.
Ex.No: 8(b) DIVIDE BY ZERO EXCEPTION HANDLING

AIM:
To write a PL/SQL program to divide by zero exception handling.

PROGRAM:

SQL> declare
2 l_num1 number;
3 l_num2 number;
4 begin
5 l_num1:=10;
6 l_num2:=0;
7 dbms_output.put_line(‘result:’||l_num1/l_num2);
8 exception
9 when zero_divide then
10 dbms_output.put_line(sqlcode);
11 dbms_output.put_line(sqlerrm);
12 End;
13/
OUTPUT:

-1476
ORA-01476: divisor is equal to zero
PL/SQL procedure successfully completed.

RESULT:
Thus the PL/SQL program for exception handling was written , executed and the output was verified successfully.
Ex.No:9 DATABASE DESIGN USING E-R MODEL AND NORMALIZATION

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

In the ORDER Relation: OrderNum is the Key.


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
• Solution: Introduce a third Intersection relation and copy keys from original two relations.
Relationships. Many to Many relationships can not be directly
implemented in 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.

RESULT:
Thus the ER Database design using E-R model and Normalization was implemented successfully.
Ex No:10 DATABASE DESIGN AND IMPLEMENTATION PAY ROLL PROCESSING

STEPS:
1. Create a database for payroll processing which request the using SQL
2. Establish ODBC connection
3. In the administrator tools open data source ODBC
4. Click add button and select oracle in ORA home 90, click finish
5. A window will appear given the data source home as oracle and select TNS source name as lion and
give the used id as SWTT
6. ADODC CONTROL FOR SALARY FORM:-
7. The above procedure must be follow except the table , A select the table as salary
8. Write appropriate Program in form each from created in VB from each from created in VB form
project.
SQL>create table emp(eno number primary key,enamr varchar(20),age number,addr varchar(20),DOB
date,phno number(10));
Table created.
SQL>create table salary(eno number,edesig varchar(10),basic number,da number,hra number,pf
number,mc number,met number,foreign key(eno) references emp);
Table created.
TRIGGER to calculate DA,HRA,PF,MC
SQL> create or replace trigger employ
2 after insert on salary
3 declare
4 cursor cur is select eno,basic from salary;
5 begin
6 for cur1 in cur loop
7 update salary set
8 hra=basic*0.1,da=basic*0.07,pf=basic*0.05,mc=basic*0.03 where hra=0; 9 end loop;
10 end;
/
Trigger created.

PROGRAM FOR FORM 1


Private Sub emp_Click()
Form 2.Show End
Sub Private
Sub exit_Click()
Unload Me
End Sub Private
Sub salary_Click()
Form3.Show
End Sub

PROGRAM FOR FORM 2


Private Sub add_Click()
Adodc1.Recordset.AddNew MsgBox "Record added"
End Sub Private
Sub clear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub Private Sub delte_Click()
Adodc1.Recordset.Delete MsgBox "Record Deleted"
If Adodc1.Recordset.EOF = True
Then Adodc1.Recordset.MovePrevious
End If
End
Sub Private Sub exit_Click()
Unload Me
End Sub
Private Sub main_Click()
Form1.Show
End Sub
Private Sub modify_Click()
Adodc1.Recordset.Update
End Sub

PROGRAM FOR FORM 3


Private Sub add_Click()
Adodc1.Recordset.AddNew MsgBox "Record added"
End Sub
Private Sub
clear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
Private Sub delte_Click()
Adodc1.Recordset.Delete MsgBox "Record Deleted"
If Adodc1.Recordset.EOF = True
Then Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Private Sub main_Click()
Form1.Show
End Sub
Private Sub
modify_Click()
Adodc1.Recordset.Update
End Sub
Output:
RESULT:

Thus payroll system was designed and implemented successfully.

You might also like