0% found this document useful (0 votes)
10 views

Dbms

Data base management system

Uploaded by

ramuk612001
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Dbms

Data base management system

Uploaded by

ramuk612001
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Ex.No:1 A.

BASIC MYSQL OPERATIONS

Date:

AIM:

To perform basic my sql operations by creating new table.

PROCECDURE:

Step: 1

Create the student table with the attributes of sno, sname, major,
and age setting the primary key wherever needed.

Step:
2

Alter the structure of the table using the conditions.

Step: 3

Insert corresponding values into the table

Step: 4

Delete the values based on constraints.

Step: 5

Delete the values based on conditions given.

Step: 6

Display the values using various types of select clauses.

Step :7

Removing the table using the command.


Step: 8

Display the values using various forms of select statements .


Step9

Display the values using various forms of sorting.

Step : 9

Drop the table using the corresponding command.

Step : 10

End
A. To create the table and setting the primary key using the above

relations:

create database iibca;

use iibca;

create table student (sno integer,sname varchar(20),mark integer, age

integer,dob date, primary key(sno));

B. Alter the Structure Of The Table

1. alter table student add dob date

2. desc student

3. alter table student modify sname varchar(25)

4. alter table student change sno snum integer

5. alter table student drop dob

6. Select name from student order by mark

7. Select snum, sname from student order by mark desc


1.

RESULT:

Thus the above program has been done and the result is obtained
successfully

----------------------------------------------------------------------------------------------------------------
Ex. No: 2 Set Operations

Date:

Develop mysql queries to implement the following set operations


a) Union
b) Union all
c) Intersect
d) Intersect all

AIM:

To develop mysql queries to implement set operations.

PROCEDURE:

Step: 1

Create the employee table with the attributes of empno, ename,

Basicpay , location, deptno.

Step: 2

Create table dept with the attributes of empno, deptno,designation .

Step: 3

Insert corresponding values into the tables.

Step: 4

Perform the set operations using the above tables.

Step: 5

END.
The following relations keep track of Employee information:

Emp (empno: integer, ename: string, deptno: integer, Badicpay: integer,


location:string)

Dept (Empno: integer, deptno: integer, designation: string)

Create table emp(empno integer primary key, ename varchar(20), deptno integer not null,
basicpay integer, location varchar(20));

Create table dept(empno integer primary key,ename varcchar(20).,deptno integer, references


emp(deptno), designation varchar(20));

Insert into emp values(1000,’anitha’, 20000,’kumbakonam’,10);

Insert into emp values(1001,’anusha’, 40000,’aaduthurai’,20); Insert

into emp values(1002,’ananth’, 14000,’mannargudi’,10); Insert into

emp values(1003,’mohamed’, 20000,’thanjavur’,30); Insert into dept

values(1004,’ravi’, 20000,’kumbakonam’,30);
Insert into dept values(1000,’amutha’, 15000,’kuthalam’,10); Insert

into emp values(1001,’anitha’, 30000,’aaduthurai’,20); Insert into

emp values(1000,’amutha’, 15000,’mannargudi’,10); Insert into emp

values(1000,’mohamed’, 20000,’thanjavur’,30); Insert into emp

values(1000,’ravi’, 20000,’kumbakonam’,30);

Write each of the following queries in SQl:

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:

To perform aggregate function using mysql.

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

Insert the corresponding values into the corresponding table.

Step: 4

Execute the queries for the following questions.

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:

1. create database exe3;

2. use exe3;

3. create table faculty(fid integer,fname varchar(20),dept varchar(20),salary integer,

primary key(fid));

INSERT VALUES

insert into faculty values(201,'a','bca',72000); insert

into faculty values(202,'b','bca',40000); insert into

faculty values(203,'c','music',50000); insert into

faculty values(204,'d','biology',59000); insert into

faculty values(205,'e','cs',69000); insert into faculty

values(206,'w','cs',43000); insert into faculty

values(207,'j','bca',66000);

DISPLAY VAUES USING SELECT CLAUSE

select * from faculty;

Fid fname dept salary

201 A bca 72000

202 B bca 40000

203 C music 50000

204 D biology 59000

205 E cs 69000

206 W cs 43000

207 J bca 66000


A) SUM

select sum(salary) from faculty;

sum(salary)
399000

B) COUNT
select count(*) from faculty;

count(*)
7

select count(dept) from faculty;

count(dept)
7
select count(distinct dept) from faculty;

count( distinct dept)


4

C) AVERAGE

select avg(salary) from faculty;

avg(salary)
57000

select avg(salary) from faculty where dept='cs';

avg(salary)
56000

select avg(salary) from faculty where dept='bca';

avg(salary)
59333.33
D) MAXIMUM

select max(salary) from faculty;

max(salary)
72000

E) MINIMUM

select min(salary) from faculty;

min(salary)
40000

F) GROUP BY CLAUSE & HAVING CLAUSE

select dept ,count(distinct fid) as fac_count from faculty group by dept;

dept fac_count
bca 3
biology 1
cs 2
music 1

select dept ,count(distinct fid) as fac_count from faculty group by dept

having count(distinct fid)>=3;

dept fac_count
bca 3

select dept ,count(distinct fid) as fac_count from faculty group by dept

having count(distinct fid)>=4;

Empty set (0.00 sec)


RESULT:

Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------------------
.
Ex.No:4 JOIN OPERATIONS

Date:

================================================================

AIM:

To display records using various types of join operations.

PROCECDURE:

Step: 1

Create the student table with the attributes of studid, name,

Deptname and fees paid

Step: 2

Create the fees table with the attributes of studid, course fees,

bus fees, concession, total fees.

Step: 3

Insert the corresponding values into the corresponding tables.

Step: 4

Execute the queries for the following questions.

Create the above tables by properly specifying the primary keys & foreign
keys.

i) Enter at least five tuples for each relation.

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));

ii. Enter at least five tuples for each relation.

Insert into student values (1000,’ASHICK’,’BCA’, 2000,’PAID’);

Insert into student values (1001,’AARTHI’,’BCA’, 0,’PAID’); Insert

into student values (1002,’AVINASH’,’CS’, 1000,’PAID’); Insert into

student values (1003,’ABI’,’BCOM’, 2000,’NOTPAID’); Insert into

student values (1004,’SHILPA’,’IT’, 0,’PAID’);

Insert into fees values (1000,’MAYILADURAI’,’COLLEGEBUS’);

Insert into fees values (1001,’KUMBAKONAM’,’OUTBUS’); Insert

into fees values (1002,’MANNARKUDI’,’COLLEGEBUS’);

Insert into fees values (1003,’VAITHEESWARANKOVIL’,’OUTBUS’);

Insert into fees values (1004,’SIRKALI’,’COLLEGEBUS’);


iii. Give the details of the student fees details using inner join operations.

Select student.studentid, student.deptname, fees.city from student inner join fees on


student.studentid = fees.studentid;

IV) Find the student from BCA who has fees concession using left join.

Select student.studentid, student.deptname, fees.city from student left join fees on


student.studentid = fees.studentid where student.feesconcession>0 and student.deptname
=’BCA’;

V) Display the students from all the departments using right join.

Select student.studentid, student.deptname, fees.city from student right join fees on


student.studentid = fees.studentid where student.feesconcession>0;

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:

To display records using various types of sub queries operations.

PROCECDURE:

Step: 1

Create the student table with the attributes of studid, name,

Deptname and fees paid

Step: 2

Create the fees table with the attributes of studid, course fees,

bus fees, concession, total fees.

Step: 3

Insert the corresponding values into the corresponding tables.

Step: 4

Execute the queries for the following questions.


Create the above tables by properly specifying the primary keys & foreign
keys.

i) Perform queries using ‘ in’ and ‘not in’

ii) Perform the queries using some and all.

iii) Sub queries operations using exists and not exists.

iv) Perform the queries unique and not unique.


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);

Create table fees (studentid integer primary key, city varchar (10) not null,
collegebus varchar(12) not null, foreign key(studentid)references
student(studentid));

ii. Enter at least five tuples for each relation.

Insert into student values (1000,’ASHICK’,’BCA’, 2000,’PAID’);

Insert into student values (1001,’AARTHI’,’BCA’, 0,’PAID’);

Insert into student values (1002,’AVINASH’,’CS’, 1000,’PAID’);

Insert into student values (1003,’ABI’,’BCOM’, 2000,’NOTPAID’);

Insert into student values (1004,’SHILPA’,’IT’, 0,’PAID’);

Insert into fees values (1000,’MAYILADURAI’,’COLLEGEBUS’);

Insert into fees values (1001,’KUMBAKONAM’,’OUTBUS’);

Insert into fees values (1002,’MANNARKUDI’,’COLLEGEBUS’);

Insert into fees values (1003,’VAITHEESWARANKOVIL’,’OUTBUS’);

Insert into fees values (1004,’SIRKALI’,’COLLEGEBUS’);


a) Sub queries using ‘in’ and ‘not in’

1. Display the details of students who have paid the fees if they are in
the Department BCA and IT.

Select * from student where deptname in (‘BCA’,’IT’);

2. Display the name of the students who have not paid the fees except from
bca and it department.

Select ename from student where deptname not in (‘bca’,’it’);

b) Set comparison using ‘some’ and ‘all’

select ename from student where student.studentid<> some(select student.studentid from


fees from student);

c) relation (exists, not exists)

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

Create table student with the attributes of sno,sname,address,mark.

Step: 2

Insert the corresponding values into the table.

Step: 3

Execute the queries for the following questions.

Step:4

End
Create the tables by properly specifying the primary keys & foreign keys.

1. Developing queries using % operator.

2. Sort records using asc and desc.

Create the table and insert the values.

create database bca;

use bca

create table student (sno integer, sname varchar(20), address varchar(30), mark integer,
primary key(sno));

insert into student values (101,’saravanan’,’KUMBAKONAM’);

insert into student values (102,’kalyani’,’aduthurai’);

insert into student values (103,’Sowmiya’,KUTHALAM’); insert

into student values (104,’ANIE’,’MANNARKUDI’); insert into

student values (105,’RAMESH’,’KUMBAKONAM’); insert into

student values (106,’ KANNAN’,’KUMBAKONAM’); Queries

using % operator.

Select sno,sname,address from student where sname like ‘A%’;

Sort records in Ascending and descending

Sort sname address from student;

Sort sname, address from student desc;


RESULT:

Thus the above program has been done and the result is obtained
successfully

------------------------------------------------------------------------------------------------------
Ex.No:7 VIEW OPERATIONS

Date:

AIM:

Create the database and tables for bank database.

PROCECDURE:

Step: 1

Create the bbranch table with the attributes of branch-name,

branch- city, assets number.

Step: 2

Create a view for the corresponding table with queries.

Create the bbranch table with the attributes of branch-

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);

ii. Enter at least five tuples for each relation.

Insert into student values (1000,’ASHICK’,’BCA’, 2000,’PAID’);

Insert into student values (1001,’AARTHI’,’BCA’, 0,’PAID’); Insert

into student values (1002,’AVINASH’,’CS’, 1000,’PAID’); Insert into

student values (1003,’ABI’,’BCOM’, 2000,’NOTPAID’); Insert into

student values (1004,’SHILPA’,’IT’, 0,’PAID’);

1. Develop MySQL queries to create views and expand it.

Create view stu as select stuid,name from student where concession=1000;


RESULT:

Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------------------
EX.No:8 EXCEPTION HANDLING

Date:

AIM:

Create the PLSQL block with procedure.

PROCECDURE:

Step: 1

Step: 2

Step: 3

Step: 4

Create the ddepositer table with the attributes of customer name,

Customer name, accno.

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

<declaration of variables, constants, function, procedure,

cursor etc.>;
begin
<executable statement(s)>;
exception
<exception handling>; end;
/

Example
Begin
Insert into emp(empno,ename) values(100,’Shruti’);

Insert into emp(empno,ename) values(101,’Yesha’);

End;

/
SQL>Set Server output On
DECLARE

Sample_exception EXCEPTION;

PROCEDURE nested_block

IS

BEGIN

Dbms_output.put_line(‘Inside nested block’);

Dbms_output.put_line(‘Raising sample_exception from nested block’);

RAISE sample_exception;

EXCEPTION

WHEN sample_exception THEN

Dbms_output.put_line (‘Exception captured in nested block. Raising to main block’);

RAISE,

END;

BEGIN

Dbms_output.put_line(‘Inside main block’);

Dbms_output.put_line(‘Calling nested block’);

Nested_block;

EXCEPTION

WHEN sample_exception THEN

Dbms_output.put_line (‘Exception captured in main block');

END:

/
RESULT:

Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------------------
EX.No:9 CURSORS AND TRIGGERS

Date:

AIM:

Create the PLSQL block using cursors and triggers.

PROCECDURE:

Execute the queries for the following questions.


/* Cursors */

DECLARE

CURSOR c1 is

SELECT ename, empno, sal FROM emp

ORDER BY sal DESC;

my_ename VARCHAR2(10);

my_empno NUMBER(4);

my_sal NUMBER(7,2);

BEGIN

OPEN c1;

FOR i IN 1..5 LOOP

FETCH c1 INTO my_ename, my_empno, my_sal;

EXIT WHEN c1%NOTFOUND; /* in case the number requested */

/* is more than the total */

/* number of employees */

INSERT INTO temp VALUES (my_sal, my_empno, my_ename);

COMMIT;

END LOOP;

CLOSE c1;

END;
Test Output:
/* TRIGGERS */
/* BEFORE
creating this trigger you have to first create the table student with field age */

CREATE OR REPLACE TRIGGER age_changes


BEFORE DELETE OR INSERT OR UPDATE ON student
FOR EACH ROW
WHEN (NEW.CODE > 0)
DECLARE
age_diff number;
BEGIN
age_diff := :NEW.age - :OLD.age;
dbms_output.put_line ('Prevoius age: ' || : OLD.age);
dbms_output.put_line ('Current age: ' || : NEW.age);
dbms_output.put_line ('Age difference: ' || age_diff);
END;
/

Output

INSERT INTO STUDENT VALUES (4, 'MARY', 16, 97);

RESULT:

Thus the above program has been done and the result is obtained
successfully
---------------------------------------------------------------------------------------------

eX.No:10 Indexing
Date:

AIM:

Create the PLSQL block using different types of Indexing

PROCECDURE:
Execute the queries for the following questions.

a. Creating index for single column of the table:

1, CREATE INDEX idx_stuno ON student (rollno);

b. Creating index for multiple columns of the table.

CREATE INDEX idx_pname ON student (LastName, FirstName);

c.

You might also like