0% found this document useful (0 votes)
178 views14 pages

7 - SQL Based Question in RDBMS

Uploaded by

Sunil Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
178 views14 pages

7 - SQL Based Question in RDBMS

Uploaded by

Sunil Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 14
Unit 3 : Database Management System Previous Year Questions Based on SQL Commands ) . ® Write the query to create a table with following structure. Table Product Field Datatype PID Char(4) Pname Varchar(20) Description Varchar(40) Price Decimal Create table Product ( PID Char(4), Pname Varchar(20), Description Varchar(40), Price Decimal y Consider the following table employee: Employee ce EmpNo EmpName Designation 1 Sahil A 2 Amp OB ® 3 Mansi 4 Pooja 1.Which of the following field can be selected as Primary Key? 2. EmpName field also has unique values for all the records. Can it be made primary key? Give answer with reason. w|>|o (i) | Which of the following field can be selected as Primary Key? Ans. EmpNo can be selected as a primary key. (ii) EmpName field also has unique values for all the records. Can it be made primary key? Give answer with reason. Ans. EmpName is having unique values, but there is no guarantee that if more employees are included then there would not be multiple people with similar names. So, in future its values may be duplicate. Thus, it cannot be made as a primary key. ,, Categorize the following commands as Boor and DML: SELECT, ALTER, INSERT, DROP eZ DDL — ALTER , DROP DML - SELECT , INSERT (Ora | | Create the following table items. Column name Data type Size Constraint Itemno Integer Primary key Iname Varchar 15 Price Numeric 10, 2 Quantity Integer 3 a Create table items ( Itemno integer Primary key, Iname varchar(15), Price numeric(10,2), Quantity integer(3) ) Consider the following table Item and write the queries from (i) to (iii) © Table: Item | Itemno Iname | Price Quantity im Soap 40 80 [22 Powder 80 30 [33 Facecream | 250 [25 [44 Shampoo | 120 100 [5s Soapbox 20 50 i. Write a command to insert a new record with the following values : (66, ‘Gel’, 150, 70). ii. Write a query to display all the record of table Item whose price is in the range of 100 and 300. iii. Write a query to display all the records of a table in descending order of quantity. (i) -~ Write a command to insert a new record with the following values : (66, “Gel’, 150, 70). Ans. Insert into item values(66, ‘Gel’, 150, 70); (ii) Write a query to display all the record of table Item whose price is in the range of 100 and 300. Ans. Select * from item where price between 100 and 300; OR Select *from item where price >=100 and price <=300; (iii) Write a query to display all the records of a table in descending order of quantity. Ans. Select * from item order by quantity desc; Consider the following Vendor table and write the queries. Table Vendor VendorlD | VName DateofRegistration | Location 001 Mother Dairy | 20-01-2009 | Dethi v002 Havmor 01-04-2015 | Gujrat vo03 Amul 12-05-2012 | Kolkata 004 Kwality Walls | 15-10-2013 Mumbai 1.Write a query to display all records. 2.Write a query to add new row with the following details. (“V005”, “Vadilal”, “2010-03-20”, “Pune“) 3.Write a query to modify the location of V003 from Kolkata to Gujrat. Ans. (ii) Ans. (iii) Ans. Write a query to display all records. Select * from Vendor; Write a query to add new row with the following details. (“V005”, “Vadilal”, “2010-03-20”, “Pune") Insert into Vendor values (“V005”, “Vadilal”, “2010-03-20”, “Pune”); Write a query to modify the location of V003 from Kolkata to Gujrat. Update Vendor Set location= “Gujrat” Where Vendorld="V003'; Write the SQL commands to answer the queries based on Fabric table. FabricID | Frame Type Disc FOO! | Shirt Woollen | 10 F002 Suit | Cotton 20 F003 | Tunic | Cotton [10 F 8 F004 Jeans Denim [5 F006 Shorts Cotton 7 1. To insert the following record (“F005”, “Kurta”, “Woollen”,5). 2. To display only those fabric whose disc is more than 10. 3. To display those record whose type is ‘Woollen’. 4. To modify the fabric shirt by increasing discount by 10. 5. To delete the record of fabric F003 from table. a. To insert the following record (“F005”, “Kurta”, “Woollen”,5) Ans : insert into Fabric values (‘FO05’, ‘Kurta’, ‘Woollen’,5); b. To display only those fabric whose disc is more than 10. Ans : select * from Fabric where Disc>10; c. To display those record whose type is ‘Woollen’ Ans : select * from Fabric where type = ‘Woollen’; d. To modify the fabric shirt by increasing discount by 10 Ans : update fabric set Disc =Disc + 10 where Fname = ‘Shirt’; e. To delete the record of fabric F003 from table Ans : delete from Fabric where FabriclD ="F003";

You might also like