Dbms
Dbms
Date:
AIM:
PROCECDURE:
Step: 1
Create the student table with the attributes of sno, sname, major,
and age setting the primary key wherever needed.
Step:
2
Step: 3
Step: 4
Step: 5
Step: 6
Step :7
Step : 9
Step : 10
End
A. To create the table and setting the primary key using the above
relations:
use iibca;
2. desc student
RESULT:
Thus the above program has been done and the result is obtained
successfully
----------------------------------------------------------------------------------------------------------------
Ex. No: 2 Set Operations
Date:
AIM:
PROCEDURE:
Step: 1
Step: 2
Step: 3
Step: 4
Step: 5
END.
The following relations keep track of Employee information:
Create table emp(empno integer primary key, ename varchar(20), deptno integer not null,
basicpay integer, location varchar(20));
values(1004,’ravi’, 20000,’kumbakonam’,30);
Insert into dept values(1000,’amutha’, 15000,’kuthalam’,10); Insert
values(1000,’ravi’, 20000,’kumbakonam’,30);
1) Find the empno and deptno of all the employees from emp and dept
tables order by deptno using union operation.
Select empno, deptno from emp union select empno, deptno from dept order by
deptno;
2) Display the employee no from both tables using union all.
3) Display the employee no, name from both tables using intersect.
Since we can't use the INTERSECT operator in MySQL, we will use the IN
operator to simulate the INTERSECT query as follows
Select emp.empno from emp where emp.empno in (SELECT dept.empno from dept);
RESULT:
Thus the above program has been done and the result is obtained
successfully.
------------------------------------------------------------------------------------------------------------------
Ex.No:3 AGGREGATE FUNCTIONS
Date:
AIM:
PROCECDURE: .
Step: 1
Create the faculty table with the attributes of fid, fname, dept &
Salary.
Step: 2
Create the course table with the attribute of ccourse, cname, Dept .
Step: 3
Step: 4
Step:5
End
Develop mysql queries to implement the following aggregate functions
a) Sum
b) Count
c) Average
d) Maximum
e) Minimum
f) Group by clause & having clause
TABLE CREARTION:
2. use exe3;
primary key(fid));
INSERT VALUES
values(207,'j','bca',66000);
205 E cs 69000
206 W cs 43000
sum(salary)
399000
B) COUNT
select count(*) from faculty;
count(*)
7
count(dept)
7
select count(distinct dept) from faculty;
C) AVERAGE
avg(salary)
57000
avg(salary)
56000
avg(salary)
59333.33
D) MAXIMUM
max(salary)
72000
E) MINIMUM
min(salary)
40000
dept fac_count
bca 3
biology 1
cs 2
music 1
dept fac_count
bca 3
Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------------------
.
Ex.No:4 JOIN OPERATIONS
Date:
================================================================
AIM:
PROCECDURE:
Step: 1
Step: 2
Create the fees table with the attributes of studid, course fees,
Step: 3
Step: 4
Create the above tables by properly specifying the primary keys & foreign
keys.
ii) Give the details of the student fees using inner join operations.
iii) Find the student from BCA who has fees concession using left join.
iv) Display the students from all the departments using right join.
i. Create the above tables by properly specifying the primary keys and
the foreign keys.
Create table student (studentid integer primary key, name varchar(30)not null, deptname
varchar(30)not null, concessionamount integer, feesstatus varchar(30) not null);
Create table fees (studentid integer primary key, city varchar (10) not null, collegebus
varchar(12) not null, foreign key(studentid)references student(studentid));
IV) Find the student from BCA who has fees concession using left join.
V) Display the students from all the departments using right join.
VI) Display the students from all the departments using right join.
Select student.studentid, student.deptname, fees.city from student FULL OUTER JOIN fees
on student.studentid = fees.studentid where student.feesconcession>0;
RESULT:
Thus the above program has been done and the result is obtained
successfully
------------------------------------------------------------------------------------------------------------------
Ex.No:5 B. Nested Sub Queries
Date:
AIM:
PROCECDURE:
Step: 1
Step: 2
Create the fees table with the attributes of studid, course fees,
Step: 3
Step: 4
Create table student (studentid integer primary key, name varchar(30)not null,
deptname varchar(30)not null, concessionamount integer, feesstatus
varchar(30) not null);
Create table fees (studentid integer primary key, city varchar (10) not null,
collegebus varchar(12) not null, foreign key(studentid)references
student(studentid));
1. Display the details of students who have paid the fees if they are in
the Department BCA and IT.
2. Display the name of the students who have not paid the fees except from
bca and it department.
Select distinct studentid, ename from student where exists ( select * from fees where
fees.city =’KUMBAKONAM’);
Select distinct studentid, ename from student where not exists ( select * from fees where
fees.city =’KUMBAKONAM’);
RESULT:
Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------------------
Ex.No:6 c. String operations
Date:
AIM:
To process the queries using operators like ‘%’ all and desc.
PROCECDURE:
Step: 1
Step: 2
Step: 3
Step:4
End
Create the tables by properly specifying the primary keys & foreign keys.
use bca
create table student (sno integer, sname varchar(20), address varchar(30), mark integer,
primary key(sno));
using % operator.
Thus the above program has been done and the result is obtained
successfully
------------------------------------------------------------------------------------------------------
Ex.No:7 VIEW OPERATIONS
Date:
AIM:
PROCECDURE:
Step: 1
Step: 2
name,
Step:3
Stop
Step 4: End
i. Create the tables by properly specifying the primary keys and the
foreign keys.
Create table student (studentid integer primary key, name varchar(30)not null, deptname
varchar(30)not null, concessionamount integer, feesstatus varchar(30) not null);
Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------------------
EX.No:8 EXCEPTION HANDLING
Date:
AIM:
PROCECDURE:
Step: 1
Step: 2
Step: 3
Step: 4
Step: 5
Step: 6
Step: 7
Step: 8
Execute the queries for the following questions
Aim : Implementing Operations on relations using PL / SQL.
PL/SQL Block
declare
cursor etc.>;
begin
<executable statement(s)>;
exception
<exception handling>; end;
/
Example
Begin
Insert into emp(empno,ename) values(100,’Shruti’);
End;
/
SQL>Set Server output On
DECLARE
Sample_exception EXCEPTION;
PROCEDURE nested_block
IS
BEGIN
RAISE sample_exception;
EXCEPTION
RAISE,
END;
BEGIN
Nested_block;
EXCEPTION
END:
/
RESULT:
Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------------------
EX.No:9 CURSORS AND TRIGGERS
Date:
AIM:
PROCECDURE:
DECLARE
CURSOR c1 is
my_ename VARCHAR2(10);
my_empno NUMBER(4);
my_sal NUMBER(7,2);
BEGIN
OPEN c1;
/* number of employees */
COMMIT;
END LOOP;
CLOSE c1;
END;
Test Output:
/* TRIGGERS */
/* BEFORE
creating this trigger you have to first create the table student with field age */
Output
RESULT:
Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------
eX.No:10 Indexing
Date:
AIM:
PROCECDURE:
Execute the queries for the following questions.
c.