0% found this document useful (0 votes)
30 views1 page

PRACADBMS

1. A stored procedure is created to accept a student roll number and return the student's highest name and percentage. 2. A stored procedure is created to take a number as input and calculate the sum of its digits. 3. A cursor is created to display employee name, department number, and salary from an EMP table. The output is formatted as employee name works in department number and earns salary.

Uploaded by

wefot57202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

PRACADBMS

1. A stored procedure is created to accept a student roll number and return the student's highest name and percentage. 2. A stored procedure is created to take a number as input and calculate the sum of its digits. 3. A cursor is created to display employee name, department number, and salary from an EMP table. The output is formatted as employee name works in department number and earns salary.

Uploaded by

wefot57202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

WAP which accepts the student roll no and returns the highest percent and Write a SQL that

e a SQL that will take a number as input and calculate sum Create a cursor for the emp table. Produce the output in following
Create a cursor for updating the salary of emp working in deptno 10 by
name of that student to the calling block. of its digits. format: {empname} employee working in department {deptno}
20%.
STUDENT(Stud_ID,Stud_name,percent); Delimiter // earns Rs. {salary}. EMP(empno, empname, salary, deptno);
If any rows are affected than display the no of rows affected. Use implicit
create table student(studId integer primary key,studName varchar(25), create procedure sumofdigits(in n int(4)) Drop table emp;
cursor.
percent decimal); begin declare r integer; create table emp(eno int primary key,ename varchar(35),
select* from emp;
insert into student values(1,'Kumud Mishra',65.25); declare s integer; salary decimal(10,2),deptno int);
Drop procedure salaryUpdate();
insert into student values(2,'Sushant Rajput',72.85); set @s = 0; insert into emp values(1,'Tony Stark',125000.00,10),
Delimiter//
insert into student values(3,'Dikvijay Singh',82.74); while @n<>0 do (2,'Peter Parker',25000.00,11),
create procedure salaryUpdate()
select * from student; set @r=@n%10; (3,'Steve Rogers',50000.00,10),(4,'Bruce Banner',35000.00,10);
begin
set @s=@s+@r; select * from emp;
declare count int;
Drop procedure findStudent; Set @n=@n div 10; declare id int;
Delimiter $$ end while; drop procedure showRecord();
declare sal decimal(10,2);
create procedure findStudent(in roll int(4), out sname varchar(25),out per decimal) select @s; delimiter //
declare finished int default 0;
begin end // delimiter ; create procedure showRecord()
declare emp_cursor cursor for select eno,salary from emp where
select studName into sname from student where studId=roll; begin
deptno=10;
select percent into per from student where studId=roll; set @n=12345; declare name varchar(255);
declare continue handler for not found set finished=1; open emp_cursor;
end $$ delimiter ; call sumofdigits(@n); declare dno int;
set count =0;
set @r=2; declare sal decimal(10,2);
get_record: loop
set @sn=' '; Write a SQL that will generate the natural series from 1 to 10. declare finished int default 0;
fetch emp_cursor into id,sal;
set @p=1.0; Delimiter // declare msg varchar(255);
if finished=1 then LEAVE
call findStudent(@r,@sn,@p); create procedure Natural_number() declare emp_cursor cursor for select ename,deptno,salary from emp;
get_record;
select @sn,@p; begin declare continue handler for not found set finished=1;
end if;
Declare n INT; open emp_cursor; set msg='';
update emp set salary=salary*1.2 where eno=id;
Write a procedure which accepts the emp no and returns the associated Declare str VARCHAR(255); get_information: loop
set count=count+1; end loop;
emp name. If emp no does not exist then give proper error message. set n=1; fetch emp_cursor into name,dno,sal;
close emp_cursor;
EMP(Empno, Empname). set str=''; if finished=1 then leave get_information;
select count; end // delimiter ;
Drop table emp; label1: Loop end if;
call salaryUpdate();
create table emp(empno int ,empname varchar(35)); IF n>10 THEN set msg=CONCAT(name," working in department ",dno," earn RS.",sal);
select * from emp;
insert into emp values(01,'Peter Parker'),(02,'Tony Stark'),(03,'Steve Rogers'), LEAVE label1; select msg; end loop;
(04,'Bruce Banner'); END IF; close emp_cursor ;
select * from emp; set str= CONCAT(str,n,','); set end //delimiter ;
n=n+1; call showRecord();
Drop procedure checkId; END LOOP;
delimiter // SELECT str; Write a Trigger that stores the old data table of student table in
create procedure checkId(in eid int(5),out ename varchar(100)) END // Delimiter ; student_backup while updating thestudent table. Student_backup
begin (Stud_ID, Stud_name, Address, Contact_no, Branch, Operation_date)
declare msg varchar(255); call Natural_number; Student (Stud_ID, Stud_name, Address, Contact_no, Branch)
set msg='Employee ID does not exist'; create table student(studId integer primary key,studName varchar(25));
select empname into ename from emp where empno=eid; Write a SQL that will generate the Fibonacci series upto7 terms. insert into student values(1,'gk');
if ename is Null then select msg; drop procedure fibo; insert into student values(2,'rs');
end if; Delimiter // select * from student;
end // delimiter ; create procedure fibo()
set @id=1; begin declare f int; create table studentBackup(studId integer primary key,
set @n=''; declare f1 int; studName varchar(25), opDate date);
call checkId(@id,@n); declare f2 int; insert into studentBackup values(1,'gk','2024-01-21');
select @n; declare n INT; select * from studentBackup;
set @id=5; set @n=''; declare str VARCHAR(255); delete from studentBackup;
call checkId(@id,@n); set @f1=0; drop trigger backupTrigger;
select @n; set @f2=1; delimiter //
Create a cursor for updating the salary of emp working in deptno 10 by 20%. set @n=0; create trigger backupTrigger before update on student for each row
If any rows are affected than display the no of rows affected. Use implicit cursor. set @str='0,1,'; begin
select* from emp; while @n<5 do insert into studentBackup set studId=OLD.studId,
Drop procedure salaryUpdate(); set @f=@f1+@f2; studName=OLD.studName,
Delimiter// set @f1=@f2; opDate=NOW(); end // delimiter ;
create procedure salaryUpdate() set @f2=@f; update student set studName='ratna' where studId=2;
begin set @str=CONCAT(@str,@f,',');
declare count int; set @n=@n+1; Write a trigger which checks the age of employee while inserting the record in emp table. If it is negative then generate the error and display proper
declare id int; end while; message.
declare sal decimal(10,2); select @str; create table employee(empId integer primary key,empName varchar(25),empAge integer);
declare finished int default 0; end // Delimiter; insert into employee values(1,'gk',25);
declare emp_cursor cursor for select eno,salary from emp where deptno=10; call Fibo(); select * from employee;
declare continue handler for not found set finished=1; open emp_cursor; drop trigger checkTrigger;
set count =0; Write a SQL that will accept a string and reverse it. Delimiter //
get_record: loop Drop procedure rString; create trigger checkTrigger before insert on employee for each row
fetch emp_cursor into id,sal; Delimiter // begin
if finished=1 then LEAVE create procedure rString (in str varchar(20), in rstr varchar(20)) declare msg varchar(50);
get_record; begin if NEW.empAge <0 then set NEW.empAge = 0;
end if; select REVERSE(@str) into @rstr; end if;
update emp set salary=salary*1.2 where eno=id; end //delimiter ; end//delimiter ;
set count=count+1; end loop; set @str='MOCK TEST'; insert into employee values(3,'cd',-5);
close emp_cursor; set @rstr=''; select * from employee;
select count; end // delimiter ; call rString(@str,@rstr);
call salaryUpdate(); select @rstr;
select * from emp;

You might also like