You are on page 1of 6
SQL PRACTICALS Ql. SID |NAME | CLAS] SECTI | IT cs PROJ_REM Ss ON 101 |Aavya |11 A 34 36 Good 102 | Chris 12 [A 29 30 Average 103 [Neetu |11 B 37 40 Excellent 104 | Raj 12. A 27 28 Average Consider the table STUDENT with the above data and define the first column SID as primary key , feed all the records in the table and then answer the following queries in MySq:- a) To count the number of students in each section. b) To display the names of the student who got “Excellent” remark in their project. c) To increase the marks of the student “vivek” in CS by 5. d) The display the names of the students ending with “a”. e) To display the details of the student whose IP marks are in the range 25 to 35. f) To display the name of the student who secured maximum marks in IT> g) To insert a new row with values (105,’Shreya’,12,’D’,40,38,’Excellent’) Q2 « Consider a database LOANS with the following table: asic TEE Fn ETC 7s aaa Sl srlssa Sorc a BESS ee ee ee a sc7ssaa/[boSu sa esa ze TS ST 5 eT La aaa arr one sp 062000 See i ‘KS. Dhall 500000 48 ‘NULL 05-03-2008 3800 ‘Answer the following questions. {Display the sum of all Loan Amounts whose Interest rate is greater than 10. {) Display the Maximum interest from Loans table. (ii) Display the count ofall loan holders whose name ends with ‘Sharma’. (iv) Display the count of all loan holders whose Interest is Null. |v) Display the Interest. wise details of Loan Account Holders. (wi) Display the Interest-wise details of Loan Account Holders with at least 10 instalments remaining Q3 . Consider the following tables: COMPANY and MODEL Table: Company Seat ee Ee Ke Okhla 2 Aland Najafgarh a Maxima Shahdara 4 Seiko Okhia 5 Ricoh Shahdara Note: > Comp_ID is the Primary Key. Table: Model CB. Ajit R. Mehta B. Kohli R. Chadha J. Kishore Cee Emteiveno st = 4 7000 mos 2 800 A167 3 1200 T024 a 1300 Note: > Model_1D is the Primary Key. 2010-05-12 2009-04-15 2009-09-23 2011-01-12 2009-10-14 > Comp_ID Is the Foreign Key referencing Comp_ID of Company table. Write SQL commands for queries (i) to (iv) and output for (v) and (vi). ()) To display details of all models in the Model table in ascending order of DateOfManufacture. (ii) To display details of those models manufactured in 2011 and whose Cost is below 2000. (ii) To display the Model_10, Comp_1D, Cost from the table Model, CompName and ContactPerson from Company table, with their corresponding Comp_| (iv) To decrease the cast of all the models in Model table (v) select count{ distinct CompHO) from Company; 10. by 15% (ui) select CompName, contact('Mr-’,ContactPerson) from Company where CompName ends with ‘a a4 - Consider the following tables: STOCK and DEALER. Table: Stock a a a CE Ball Pen 0.5 2011-03-31 oe Ball Pen 0.25 ra a a 2010-01-01 5002 Gel Pen Premium 10112514 2010-02-14 5006 GelPenClassic 101.-«S 200-22 2009-01-09 5001 Eraser Small 12005 2009-03-19 5008 Eraser Big 10260 10 2010-12-12 5009 Sharpener Classic 103 «= 1608 2010-01-23 Not > ItemNo is the Primary Key. > Dcode is the Foreign Key referencing Dcode of Dealer table. ble: Dealer 101 _Reliable Stationers 103 Class Plastics 104 Fair Deals 102 lear Deals Not > Deode is the Primary Key. Write Sal statements for the queries (i) to (iv) and output for (v) and (vi): {) To display details of all the Items in the Stock table in ascending order of Stockfate (ii) To display details of those Items in Stock table whose Dealer Code(Ocode) is 102 or quantity in ‘Stock(Qty) is more than 100. (lil) To insert a record in the Stock table with the values: (5010, ‘Pencil HB’, 102, 500, 10, 2010-01-26) (iv) To display Decode, Dname from Dealer table and Item, UnitPrice from Stock table of all the Dealers (including the dealer details that have not sold any item) (v) select count(distinct Dcode) from Stock: (vi) select Qty * UnitPrice from Stock where ItemNo=5006; as Consider the following tables PRODUCT and CLIENT TABLE: PRODUCT PID PROD_NAME MANUFACTURER PRICE 101 SOAP LAK 40 102 | SHAMPOO ABC 45 103 | FACE SOAP ABC 55 104 TALC POWDER XYZ 120 105 | CREAM XYZ 50 TABLE: CLIENT co CNAME ary PD on COsMeTiC SHOP DELHI Fwos, 06 ‘TOTAL HEALTH MUMBAI S01 2 LIVE LIFE DELHI ‘HOS: 1s PRETTY WOMAN DELHI Fwi2 16 DREAMS BANGLORE, TPO1 Write SQL commands for the statements (i) to (v). i To Display of all those clients from the table CLIENT whose city is Delhi ii. To Display the details of the product whose price is in the range of 50 to 100. iii, To Increase the price by Rs. 200 in the table Product. iv. To Display the product name in the ascending order in the table Product. v. To display product name, manufacturer, city from the table Product vi. To display the number of clients belonging to each city. and Client. vii. To display the maximim, minimum price from the table product. Q6 Write a menu driven python program for performing following operations on student table available in school database. a) Add Records b) Update Records c) Delete records d) display records e) Exiting Q7 Perform all the operations with reference to table ‘Emp’ through MySQL-Python connectivity . ) To create EMP table in company database. Structure of Emp table given below EMP (empno integer primary key, ename varchar(25) not null, salary float) b) inserting a record in ‘emp’ with help of parameterized query. C) Fetching all the records from EMP table having salary more than salary given by user at runtime. ) Updating record(s) of the table to increase salary of all employees whose salary is less than 80000 €) To delete records as per given salary by user.

You might also like