0% found this document useful (0 votes)
57 views25 pages

Index: Prac. No Date of Experiment Prac. Name

Here are the SQL commands for the given Product table: 1. Display all the products whose quantity is less than 100. SELECT * FROM Product WHERE Qty < 100 2. Display product name and price for all products. SELECT Pro_Name, Price FROM Product 3. Display details of products whose price is between 5 to 15. SELECT * FROM Product WHERE Price BETWEEN 5 AND 15 4. Display product name, quantity sold and salesman name for all products. SELECT Pro_Name, Qty, Salesman FROM Product 5. Update price to 8 of product whose name is Munch. UPDATE Product SET Price = 8 WHERE Pro_Name = 'Munch'

Uploaded by

vivek
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)
57 views25 pages

Index: Prac. No Date of Experiment Prac. Name

Here are the SQL commands for the given Product table: 1. Display all the products whose quantity is less than 100. SELECT * FROM Product WHERE Qty < 100 2. Display product name and price for all products. SELECT Pro_Name, Price FROM Product 3. Display details of products whose price is between 5 to 15. SELECT * FROM Product WHERE Price BETWEEN 5 AND 15 4. Display product name, quantity sold and salesman name for all products. SELECT Pro_Name, Qty, Salesman FROM Product 5. Update price to 8 of product whose name is Munch. UPDATE Product SET Price = 8 WHERE Pro_Name = 'Munch'

Uploaded by

vivek
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/ 25

Index

Prac. No Date of Experiment Prac. Name


10 23-8-2021 To print Fibonacci Series
11 25-8-2021 To Reverse the inputted Number
12 1-9-2021 To check that entered number is Prime or Not
13 6-9-2021 To check that entered number is Armstrong or Not
14 29-12-2021 Operation on Stack (Without Function)
15 3-1-2022 Operation on Stack (With Function)
16 17-1-2022 SQL [Table: Charity]
17 29-1-2022 SQL [Table: Empl]
18 1-2-2022 SQL [Table: LoanAccounts]
19 7-2-2022 SQL [Table: Product]
20 2-3-2022 Connectivity (Insert/Delete)
21 4-3-2022 Connectivity (Update/Search)
Example: 16

1. Write a query to insert first, second and fifth records.


 Insert into charity values(1, “Bindra”, “JAspreet” , “5B,Gomti Nagar”, “ Lucknow”, 3500.50);
 Insert into charity values(2, ……………………………………………………………………….
 Insert into charity values(5, “Krishnan”,”Vineeta”, “A-75, Adarsh Nagar”, null, null);
or
Insert into charity (p_id, lastname, firstname,Address) values (5, “Krishnan”,”Vineeta”, “A-75, Adarsh Nagar”);

2. Write a query to,


a. Display all the records.
 Select * from charity;
b. Display LastName and address of the given table.
 Select lastname,address from charity;
c. Display LastName and address of who live in Mumbai city.
 Select lastname,address from charity where city=”Mumbai”;
d. Display Detail of Mr.Arora.
 Select * from charity where lastname = “Arora”;
e. Display Contribution of Bindra.
 Select contribution from charity where lastname=”Bindra”;
f. Display the Person Id whose contribution is 3500.50.
 Select p_id from charity where contribution=3500.50;
g. Display all the records whose contribution is more than 3500.
 Select * from charity where contribution > 3500.00;
h. Display all the records whose id is less than 3.
 Select * from charity where p_id < 3;
i. Display details of person whose city is Lucknow and contribution is more than 3000.
 Select * from charity where city=”Lucknow” and contribution> 3000;
j. Display the name of person those are living in lucknow or Mumbai. (use logical or)
 Select lastname,firstname from charity where city=”Lucknow” or city=“Mumbai”;
k. Display Detail of person whose contribution between 2200 to 3100.
 Select * from charity where contribution between 2200 and 3100;
 Select * from charity where contribution >= 2200 and contribution <=3100;
l. Display name whose contribution is not mention.
 Select lastname,firstname from charity where contribution is null;
m. Display the City of Mr.Rana and Mr.Krishnan.
 Select city from charity where lastname =”Rana” or lastname=”Krishnan”;
n. Display the last name of the person whose contribution is mention.
 Select lastname from charity where contribution is not null;
o. Display all the records whose last name is ending with „a‟ character.
 Select * from charity where lastname like “%a”;
p. Display all the records whose last name is starting with „b‟ character.
 Select * from charity where lastname like “b”%;
q. Display City for all those record in which city contains „a‟ character anywhere.
 Select city from charity where city like “%a%”;
r. Display all the records that are living in Adarsh nagar.
 Select * from charity where address like “% Adarsh Nagar %”;
s. Display P_id and last name of the person as per ascending order of id.
 Select p_id, lastname from charity order by p_id asc;
t. Display last name of the person as per descending order of id.
 Select lastname from charity order by p_id desc;
u. Display all the records as per descending order of their city.
 Select * from charity order by city desc;
v. Increase the value of contribution as 500. (make Temporary change in the table)
 Select contribution+500 from charity;
w. Update the last name as Krishna who having last name as Krishnan.
 Update charity set lastname=”krishna” where lastname=”Krishnan”;
x. Update the first name as veena and city as surat whose id is 5.
 Update charity set firstname=”Veena”,city=”Surat” where p_id=5;
y. Change the contribution as 5000 whose contribution is not mentioned.
 Update charity set contribution=5000 where contribution is null;
z. Remove the complete table physically.
 Drop table charity;
Example: 17
Write a query or answer based on the given table: Empl

1. Write a query to create the given table with help of suitable data type and assign primary key to empno and ename, job fields should not
accept blank values.
 Create table empl (empno int primary key, ename varchar(20) not null, job varchar(20), mgr int, hiredate date, sal decimal(6,2),
comm Decimal(6,2), deptno int);
2. Write a query to check the structure of the table.
 Desc empl;
3. Write a query to insert 1st, 2nd and last record as per the given table.
 1st record: Insert into empl (empno, ename, job, mgr, hiredate, sal, deptno) values (8369, “Smith”, “Clerk”, 8902,”1990-12-
18”,800.00,20);
 2nd record: Insert into empl values (8499,”Anya”,”Salesman, 8698,”1991-02-20”, 1600.00, 300.00,30);
4. Write a query to display that entire employee whose commission is not mentioned in the table.
 Select * from empl where comm is null;
5. Write a query to display job title, hiredate and salary for all those employee whose salary is more than 3000. Also display the output for
the same.
 Select job, hiredate, sal from empl where sal>3000;
Output:
Job | hiredate | sal
President | 1991-11-18 | 5000.00

6. Write a query to display employee number, hiredate and department number for all those employee who joined in the month November.
Also display the output for the same.
 Select empno, hiredate,deptno from empl where monthname like ”_ _ _ _ _ 11 _ _”;
Output:
????
7. Write a query to display all those employee whose ename contain second last character as T.
 Select * from empl where ename like “%T_”;
8. Write a query to display all those employee whose job title contain exact 7 character.
 Select * from empl where job like “_ _ _ _ _ _ _”;
9. Write a query to add one more field in the given table with the name DOB with suitable data type.
 Alter table empl add DOB date;
10. Write a query to increase salary by 800 for all those employee whose job title is Salesman.
 Update empl set sal=sal+800 where job=”Salesman”;
Example: 18

Write SQL commands for the given Table “LoanAccounts”.

1. Display the details of all the loans with less than 40 installments.
 Select * form loanccounts where installements<40;
2. Display the details of all the loans whose rate of interest (intrate) is mentioned.
 Select * form loanccounts where intrate is not null;
3. Display the amounts of various loans from the table Loan Accounts. A loan amount should appear only once.
 Select distinct loanamount from loanaccounts;
4. Display the Customer Name and Loan Amount for all the loans for which the loan amount is less than 500000 or intrate is more than 12.
 Select custname, loanamount from loanaccounts where loanamount<50000 or intrate>12;
5. Display the details of all the loans whose rate of intrate are more than 11% and id less than 3.
 Select * from loanaccounts where intrate > 11.00 and accno<3;
6. Display the Customer Name and Loan Amount for all the loans for which the number of installments are 24, 36, or 48. (use in keyword)
 Select custname, loanamount from loanaccounts where installment in (24,34,48);
7. Display the details of all the loans whose rate of intrate is in the range 11% to 12%. (include both the value, use logical and operator)
 Select * from loanaccounts where intrate>=11 and intrate<=12;
8. Display the details of all the loans whose rate of intrate is in the range 11% to 12%. (include both the value, use between keyword)
 Select * from loanaccounts where intrate between 11 and 12;
9. Display the details of all the loans in the descending order of their Start Date.
 Select * from loanacccounts order by startdate desc;
10. Delete the records of all the loans of 'K P Jain'.
 Delete from loanaccounts where custname = “K P Jain”;
Example: 19

Write SQL commands for the following table Product.

Pro_Id Pro_Name Qty Price Rating Salesman


101 Dairy Milk 100 10 A1 John
102 Five Star 110 15 A1 Jack
103 Milky Bar 50 20 B1 John
104 Munch 200 5 B2 David
105 Perk 25 20 A1 Albert
106 Eclairs 75 2 B1 Sam
107 Bar One 20 5 A2 Sam
108 Borneville 90 25 A1 John
109 Mango Bite 120 1 B2 Albert
110 Coffee Bite 150 2 B1 David

1. Display product name, price and quantity of products whose price is greater the 100.
 Select pro_name, price, qty from product where price>100;
2. Display unique/distinct ratings from „Product‟.
 Select distinct rating from product;
3. Display the minimum price from Product.
 Select min(price) from product;
4. Display product name and (quantity*price) name as Total_Amt for all products.
 Select pro_name, qty*price as “Total_amt” from product;
5. Display the name of salesman whose name starts with „J‟.
 Select salesman from product where salesman like “J%”;
6. Display product name and rating whose price is between 10 and 20.
 Select pro_name, rating from product where price between 10 and 20;
7. Display product id and product name of salesman John, David and Sam.
 Select pro_id, pro_name from product where salesman in (“John”, “David”, “Sam”);
8. Display product id and name with descending order of rating.
 Select pro_id, pro_name from product order by rating desc;
9. Change the price of the Product with Qty less then 100 to Rs. 10.
 Update product set price=10 where qty<100;
10. Delete the table „Product‟.
 Drop table product;

You might also like