Index: Prac. No Date of Experiment Prac. Name
Index: Prac. No Date of Experiment Prac. Name
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
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
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;