List of Experiments/Excercises

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

LIST OF EXPERIMENTS/EXCERCISES

1. Create a Ta

1. Create a table Student_records (Student_RollNo, Student_Name, Father’s Name, Branch,


Section,

Year) and insert minimum 10 records in this Student_records Table with Primary Key
(Student_RollNo).

Create Table Student_Records

Student_RollNo char(10),

Student_Name char(20),

FatherName char(20),

Branch char(10),

section char(10),

Year char(10),

primary key(Student_RollNo)

);

Insert into Student_Records values(12,'rahul','rohit','BCA','A','1st');

Insert into Student_Records values(13,'sourabh','raj','BCA','A','1st');

Insert into Student_Records values(14,'ankit','sajan','BCa','B','1st');

Insert into Student_Records values(15,'gaurab','kunal','BCA','A','1st');

Insert into Student_Records values(16,'sajan','sandeep','BCA','B','1st');

Insert into Student_Records values(17,'sachin','sanju','BCA','A','1st');

Insert into Student_Records values(18,'abhey','aman','BCA','B','1st');

Insert into Student_Records values(19,'pankaj','aman','BCA','A','1st');

Select * from Student_Records;

SARTHAK GANDHI CAF_106 1000014715


2. Create a Table ITEM (Item_code, Item_name,
Item_qty,Item_price,Item_ManufacturingDate).Find the following query in SQL:

a. Find Item_name from this table

b. Find the Items which have Price between 1000 and 5000.

c. Find Total Number of Item of this table.


Programme:
Create Table ITEM
(
Item_code char(20),
Item_name char(20),
Item_qty char(20),

SARTHAK GANDHI CAF_106 1000014715


Item_price char(20),
Item_ManufacturingDate char(20)
);
Insert into ITEM values(01,'Item 1','1','1000','04-09-2020');
Insert into ITEM values(02,' Item 2','2','5000','12-12-2020');
Insert into ITEM values(03,' Item 3','7','100','01-01-2021');
Insert into ITEM values(04,' Item 4','5','3000','19-04-2021');
Insert into ITEM values(05,'Item 5','3','2000','12-01-2021');

Select * from ITEM ;

/* sql query */

/*a*/ SELECT Item_name from ITEM;


Select * from ITEM ;

/*b*/ SELECT Item_name FROM ITEM WHERE Item_price BETWEEN 1000 AND 5000;
Select * from ITEM ;

/*c*/ SELECT Count(Item_name) FROM ITEM;


Select * from ITEM ;

SARTHAK GANDHI CAF_106 1000014715


3. Given a Table Department_Information

Department_ID Department_Name Department_Location

101 MCA AA

102 MBA CC

103 B.Tech BB

SARTHAK GANDHI CAF_106 1000014715


104 B.Pharma DD

105 B.Arch FF

106 BCA GG

Find the following query in SQL:

a. Change the Location of Department, B.Pharma from DD to MM.

b. Delete a Record form this table which hasDepartment_Location=GG.

c. Add a Column Department_PhoneNo in this table.

d. Add a Column Department_Address in this table

e. Delete a column Department_Location from this table.

Create Table Department_Information


(
Department_ID char(20),
Department_Name char(20),
Department_Location char(20)
);

Insert into Department_Information values(101,'MCA','AA');


Insert into Department_Information values(102,'MBA','CC');
Insert into Department_Information values(103,'B.Tech','BB');
Insert into Department_Information values(104,'B.Pharma','DD');
Insert into Department_Information values(105,'B.Arch','FF');
Insert into Department_Information values(106,'BCA','GG');

Select * from Department_Information ;

/*a*/
Update Department_Information set Department_Location = 'MM' where Department_Name =
'B.Pharma' ;

Select * from Department_Information;

SARTHAK GANDHI CAF_106 1000014715


/*b*/
Delete from Department_Information where Department_location= 'GG' ;
Select * from Department_Information;

/*c*/
Alter table Department_Information Add Department_phoneNo Numeric(10);

Insert into Department_Information values(101,'MCA','AA','8854673219');


Insert into Department_Information values(102,'MBA','CC','6875329013');
Insert into Department_Information values(103,'B.Tech','BB','6754239801');
Insert into Department_Information values(104,'B.Pharma','DD','7895342178');
Insert into Department_Information values(105,'B.Arch','FF','7692134508');
Insert into Department_Information values(106,'BCA','GG','7654321977');
Select * from Department_Information;

/*d*/
Alter table Department_Information add Department_Address char(20);

Insert into Department_Information values(101,'MCA','AA','8854673219','Vedanta ');


Insert into Department_Information values(102,'MBA','CC','6875329232','Vishwakarma');
Insert into Department_Information values(103,'B.Tech','BB','672244201','Charankiya');
Insert into Department_Information values(104,'B.Pharma','DD','3495342178','Vedanta');
Insert into Department_Information values(105,'B.Arch','FF','76134508','Vastu');
Insert into Department_Information values(106,'BCA','GG','765477','Vishwakarma');
Select * from Department_Information;

/*e*/
Alter Table Department_Information drop Department_Location;
Select * from Department_Information;

SARTHAK GANDHI CAF_106 1000014715


SARTHAK GANDHI CAF_106 1000014715
4. Create a Table Employee_Salary

(Emp_id,Emp_Name,Emp_Salary,Emp_Designation)

Find the following query in SQL:

a. Find the name of employee which is getting minimum salary

SARTHAK GANDHI CAF_106 1000014715


b. Find the name of employee which is getting Maximum salary

c. Find the name of employee which has salary more than 10000.

d. Find the name of employee which has salary >25000

e. Find the Total Salary of all Employees.


Programme:

create table employee_info


(
emp_id numeric(6),
emp_name char(20),
emp_city char(20),
emp_contact_info numeric(10),
emp_salary numeric(20),
emp_designation char(20),
primary key (emp_name)
);
--insert some values
insert into employee_info values(1,'ajay','dehradun',9796569,100,'worker');
insert into employee_info values(2,'rahul','dehradun',9796679,1000,'worker');
insert into employee_info values(3,'anuj','dehradun',9796678,120000,'worker');

--(a)
select emp_name from employee_info where emp_salary in
(select min(emp_salary) from employee_info);

--(b)
select emp_name from employee_info where emp_salary in
(select max(emp_salary) from employee_info);

--(c)
select emp_name from employee_info where emp_salary > 10000;

--(d)
select emp_name from employee_info where emp_salary > 25000;

--(e)
select emp_id,sum(emp_salary) as 'total salary' from employee_info

SARTHAK GANDHI CAF_106 1000014715


5. Write a Program to Create, update, drop, and alter view Operation.
--CREATE:

Create Table Student_Records


(
Student_RollNo char(10),
Student_Name char(20),
FatherName char(20),
Branch char(10),
section char(10),
Year char(10),
primary key(Student_RollNo)
);

Insert into Student_Records values(01,'Ankit','suresh','Bsc','A','1');


Insert into Student_Records values(02,'Mhesh','Sagar ','Bsc','A','3');
Insert into Student_Records values(03,'Rakesh','Vinod ','Btech','A','1');
Insert into Student_Records values(04,'Nitesh ','Ashok ','BCA','A','2');
Insert into Student_Records values(05,'Abhishek','Anmol ','BBA','A','4');

Select * from Student_Records;

--UPDATE:
Update Student_Records set FatherName ='Mahendra ' where Student_RollNo = 05;
Select * from Student_Records;

--Drop:
Alter Student_Records drop section;

SARTHAK GANDHI CAF_106 1000014715


Select * from Student_Records;

Alter Student_Records drop section;


Select * from Student_Records;

SARTHAK GANDHI CAF_106 1000014715


SARTHAK GANDHI CAF_106 1000014715
6. Write a Program to Implement Cursor Operation
Create Table Employee
(
ID char(10),
NAME char(20),
AGE char(20),
ADDRESS char(20),
SALARY char(20),

primary key(ID )
);

SARTHAK GANDHI CAF_106 1000014715


Insert into Employee values(101,'Rohan','23','Aligarh','5000');
Insert into Employee values(102,'Suresh','22','Rampur','2200');
Insert into Employee values(803,'Mahesh','24','Ghaziabad','4000');
Insert into Employee values(154,'Chandu','25','Noida','6000');
Insert into Employee values(985,'Anmol','21','Saharanpur','8000');
Insert into Employee values(116,'Sumit','20','Delhi','3000');

Select * from Employee;

DECLARE
total_rows number(2);
BEGIN
UPDATE Employee
SET salary = salary + 2000;
IF sql%notfound THEN
dbms_output.put_line('no Employee updated');
ELSIF sql%found THEN
total_rows := sql%rowcount;
dbms_output.put_line( total_rows || ' Employee updated ');
END IF;
END;
/

Select * from Employee;

7. Write a Program in PL/SQL to print 1 to 10 using while loop.


Declare

SARTHAK GANDHI CAF_106 1000014715


I number;

Begin

    I:=1;

While (I<=10)

Loop

    Dbms_output.put_line(I);

    I:=I+1;

End loop;

End;

SARTHAK GANDHI CAF_106 1000014715


8. Write a Program in PL/SQL to find Prime and Nonprime Number.

declare

-- declare variable n, i

-- and temp of datatype number

n number;

i number;

temp number;

begin

-- Here we Assigning 10 into n

n := 13;

-- Assigning 2 to i

i := 2;

SARTHAK GANDHI CAF_106 1000014715


-- Assigning 1 to temp

temp := 1;

-- loop from i = 2 to n/2

for i in 2..n/2

loop

if mod(n, i) = 0

then

temp := 0;

exit;

end if;

end loop;

if temp = 1

then

dbms_output.put_line('true');

else

dbms_output.put_line('false');

end if;

end;

-- Program End

SARTHAK GANDHI CAF_106 1000014715


9. Write a Program in PL/SQL to find out the square of a number.
DECLARE

   a number;

PROCEDURE squareNum(x IN OUT number) IS


BEGIN

  x := x * x;

END;
BEGIN

   a:= 2;

   squareNum(a);

SARTHAK GANDHI CAF_106 1000014715


   dbms_output.put_line(' Square of (2): ' | |  a);

END;

10. Write a Program to Implement Trigger Operation.


Create Table Employee
(
ID char(10),
NAME char(20),
AGE char(20),
ADDRESS char(20),
SALARY char(20),

SARTHAK GANDHI CAF_106 1000014715


primary key(ID)
);

Insert into Employee values(101,'Rohan','23','Aligarh','5000');


Insert into Employee values(102,'Suresh','22','Rampur','2200');
Insert into Employee values(803,'Mahesh','24','Ghaziabad','4000');
Insert into Employee values(154,'Chandu','25','Noida','6000');
Insert into Employee values(985,'Anmol','21','Saharanpur','8000');
Insert into Employee values(116,'Sumit','20','Delhi','3000');

Select * from Employee;


CREATE or replace TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON Employee
FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;

SARTHAK GANDHI CAF_106 1000014715


dbms_output.put_line('Old salary:' || :OLD.salary);
dbms_output.put_line('New salary:' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;
/

INSERT INTO Employee (ID,NAME,AGE,ADDRESS,SALARY)


VALUES (7, 'Tushar', 22, 'Dehradun', 5500 );
Select * from Employee;

UPDATE Employee
SET salary = salary + 500
WHERE id = 2;
Select * from Employee;

SARTHAK GANDHI CAF_106 1000014715


By— Sarthak Gandhi

SARTHAK GANDHI CAF_106 1000014715

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy