0% found this document useful (0 votes)
41 views16 pages

Adobe Scan 07 May 2025

The document consists of multiple SQL worksheets covering various SQL commands related to database management, including DDL (Data Definition Language) and DML (Data Manipulation Language) commands. It includes exercises on creating databases, tables, inserting, updating, and deleting records, as well as questions about SQL concepts and constraints. Additionally, it addresses the relationships between SQL and MySQL, and provides practical examples for users to practice their SQL skills.
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)
41 views16 pages

Adobe Scan 07 May 2025

The document consists of multiple SQL worksheets covering various SQL commands related to database management, including DDL (Data Definition Language) and DML (Data Manipulation Language) commands. It includes exercises on creating databases, tables, inserting, updating, and deleting records, as well as questions about SQL concepts and constraints. Additionally, it addresses the relationships between SQL and MySQL, and provides practical examples for users to practice their SQL skills.
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/ 16

My SQL Worksheet-1

(DDL - Database Related commands)


1. If a database "Employee" exists, which MySql command helps you to start working in that
database?

2 Write MySql command will be used to open an already existing database "LIBRARY".

3 Write MySql command to open an existing database.

4 What does SQL stand for? What is MySQL?

5. Write two examples of DBMS software.

6. Sharmila wants to make the database named COMPANY' active. Write MySQL commands for it.

7 What is MySQL ?

8 What is the relationship between SQL and MySQL?

9 Mention any two example of common Database Management System.

10. Suggest Archana suitable command for the following purpose:


0. To display the list of the database already existing in MySQL.
To use the database named City.
To remove the pre-existing database named Clients.
0.

ii

11. Write the command to display the name of the active database.

12. Write the command to create a new database "School"


My SQL Worksheet-2
(DDL - Table Related commands excluding Altr
1 Write an SQL query to create the table 'Menu' with the following structure:
Field Type Constraint
ItemCode Varchar(5) Primary Key
ItemName Varchar(20)
|Category Varchar(20)
Price Decimal(5.2)

2 Can a table have multiple primary keys? Can it have multiple foreign keys?

3 In a Student table, out of Roll Number, Name, Address which column can be set
why?

4. Ms. Mirana wants to remove the entire content of a table "BACKUP" alongwith its
the storage space. What MySql statement should she use ?

5. Write MySgl command to create the Table STOCK including its Constraints.
Table STOCK:
Name of Column Type Size Constraint

ld Decimal Primary Key


Name Varchar 20

Company Varchar 20

Price Decimal 8 Not Null

6 Write one similarity and one difference between CHAR and VARCHAR data types.

7 Saumya had previously created a table named Product' in a database using MySQl
forgot the table structure. Suggest her suitable MySQL command through which st
structure of the already created table.

8 Roliwants to list the names of all the tables in her database named 'Gadgets'. Whic
should use to get the desired result.

9 Name the SQL commands used to :


() Physically delete a table from the database.
() Display the structure of a table.
10. Write one similarity and one difference between UNIQUE and PRIMARY KEY Constraints.

11. An attribute A of datatype varchar(20) has the value "Amit". The attribute B of datatype char(20) has
value "Karanita" . How many characters are occupied in attribute A ? How many characters are
occupied in attribute B?

12. Mrs. Sharma is the classteacher of Class XII A' She wants to create a table 'Student'
to store details of her class.
i) Which of the following can be the attributes of Student table?
a) RollNo b) "Amit" c) Name d) 25
i) Name the Primary key of the table 'Student'. State reason for choosing it.

13. Write SQL query to create a table Player' with the following structure:
Field Type Constraint
playerid Integer Primary key
name Varchar(50)
height Integer
weight Integer
datebirth Date
teamname Varchar(50)

14. Anita has created the following table with the name Order'.
Table : Order

Column Name Constraint

Orderld Primary Key


OrderDate Not Null
OrderAmount
Storeld
One of the rows inserted is as follows:
Orderld OrderDate OrderAmount Storeld

O101 2015-02- 12 34000 S104


() What is the data type of columns Orderld and OrderDate in the table Order ?
(i) Anita is now trying to insert the following row:
Orderld OrderDate OrderAnmount Storeld

O102 NULL 59000 SI0S


Will she be able to successfully insert it ? Give reason.

15. Write SQL query to create a table 'Event' with the following structure:
Field Type Constraint
Eventld Varchar(5) PRIMARY KEY
EventName Varchar(30) NOT NULL
Location Varchar(50)
ClientlD Integer
EventDate Date

16. Observe the given table carefully and answer the following questions:
PanNo Name Phoneno Address
CIZPW123A Rajesh Kumar 9599123456 WZIl - Rajouri
Garden, Delhi
ABWQ2341B Hemant Kumar 9812345678 Modern
Apartments,
Pitampura, Delhi
DERA9786T Naveen Sharma 7868654235 CA 22, Sector 21
Robini.Delhi
PARD3457L Sourabh Vena 893321 7645 JD 61,
Sector20,Gurgaon
GDTFS762P Nishant Kumar NULL Modern
Apart1ments,
Pitampura, Delli
MERT2376G Hemant Kumar 9811110891 F40, Sector 19,
Rohini, Delli
i. Name the column that might have a Primary Key constraint. Justify your answer.
ii. Name the column that might have a Unique constraint. Justify your answer.

17. "ABC" Event Management Company requires data of events that are to be organized. Write SQL query
to create a table 'Event' with the following structure
Field Type Constraint

Eventld Integer Primary key


Event Varchar( 50)

DateEvent Date

NumPerformers Integer
18. suggest her suitable command for the following purpose:
iv. To display the list of the database already existing in MySQL.
V To use the database named City.
vi. To remove the pre-existing database named Clients.
vii. To remove allthe records of the table named "Club" at one go along with its structure
permanently.

19. While creating a table named "Employee", Mr. Rishi got confused as which data type he should chose
for the column "EName" out of char and varchar. Help him in choosing the right data type to store
employee name. Give valid justification for the same.
My SQL Worksheet-3
(DDL - Ater Table commands)
1. Sahil created a table in Mysql. Later on he found that there should have been another column in the
table. Which command should he use to add another column to the table?

2. While creating a table 'Customer Simrita forgot to set the primary key for the table. Give the statement
which she should write now to set the column 'CustiD' as the primary key of the table?

3. Kuhu has already created a table Hospital' as shown below:


Patient_ No Patient_Name Disease Age Charges
PO01 Alya Viral Fever 14 500
PO02 Kavita Lung Infection 16 1500
PO03 Manya Cough and Cold 20 500
PO04 Amar Bone Fracture |22 2500
PO05 Deep Viral Fever 15 500
Now she wants to add a new column 'Address' to the above given table. Suggest suitable MySQL
command for the same.

4. Write SQL Command to remove column named 'Hobbies' from a table named 'Student'.

5
While creating the table Student last week, Ms. Sharma forgot to include the column Game_Played.
Now write a command to insert the Game_Played column with VARCHAR data type and 30 size into
the Student table?

6. Kunal created the following table with the name 'Friends':


Table : Friends
Ceiaadado Wekiae
F101 Bijoy Swimming
F102 Abhinav Reading books
F103 Jyotsna Dancing
Now, Kunal wants to delete the Hobbies' column. Write the MySQL statement

|7. Rashi wants to add another column 'Hobbies' with datatype and size as VARCHAR(50) in the already
existing table 'Student'. She has written the following statement. However it has errors. Rewrite the
correct statement.
MODIFY TABLE Student Hobbies VARCHAR;

8. Ms. Shalini has just created a table named "Employee" containing columns
Ename, Department, Salary.
After creating the table, she realized that she has forgotten to add a primary key column in the table.
Help her in writing SQL command to add a primary key column empid. Also state the importance of
Primary key in a table.

|9. While creating a table 'Customer' Simrita wrongly added a primary key constraint to the field
"CUSTNAME". Now she wants to remove the primary key constraint from the custname field. Help her
in writing the correct command.

10 Mr. Akshat have added a not null constraint to the "name" field in "employees" table. But now he wants
to remove that not null constraint. Write the command to delete the not null constraint from name
field.
Informatics Practices
My SQL Worksheet-4
(DML - INSERT INTO commands)
1. Rama is not able to change a value in a column to NULL. What constraint did she specify when she
created the table?

|2. Consider the table RESULT given below.


Table : Result
No Name Stipend Subject Average Division
1 Sharon 400 English 38 THIRD
Write command to insert a new row
6, "Mohan", 500, "English", 73, "Second"

3. Consider the Table SHOPPE given below.


Table SHOPPE
Code Item Company Qty City Price
102 Biscuit Hide & Seek 100 Delhi 10.00

To insert a new row in the table Shoppe


'110% 'Pizza', 'Papa Jones, 120, "Kolkata", 50.0

4. How is NULL value different from 0 (Zero) value?

5. Consider the following table named "GYM"


Table GYM:

ICODE INAME PRICE BRANDNAME

GIO1 Power Fit Exerciser 20000 Power Gymea


Add a new row for a new item in GYM with the details: "G107", "Vibro exerciser" ,21000, "GTCFitness"

6. What is meant by NULL value in MySQL?

7. Rewrite the following SQL statement after correcting error(s). Underline the corrections made.
INSERT IN STUDENT(RNO,MARKS) VALUE (5,78.5):

8. Rewrite the following SQL statement after correcting error(s). Underline the corrections made.
INSERT IN EMP(EMPNO, SALES) VALUE (100, 20078.50);

9. Charvi is inserting "Sharma" in the "LastName" column of the "Emp" table but an error is being
displayed. Write the correct SQL statement.
INSERT INTO Emp(Sharma')VALUES(LastName):

10. Anita has created the following table with the name 'Order'.
7

Table : Order

Column Name Constraint


Orderld Primary Key
OrderDate Not Null

OrderAmount
Storeld

One of the rows inserted is as follows:


Orderld OrderDate OrderAmount Storeld

O101 2015-02- 12 34000 SI04


() What is the data type of columns Orderld and OrderDate in the table Order ?
(i) Anita is now trying to insert the following row:
Orderld OrderDate OrderAmount Storeld

O102 NULL 59000 SI05


Willshe be able to successfully insert it ? Give reason.

11. In today's digitized world with a need to store data electronically, it is very important to store the data in
the databases. SQL is used to interact with the Database Management System.
Classify the following commands according to their type :(DDL/DML)
i. INSERT INTO ii. ALTER TABLE

12 Is NULL and 0(zero) same? Jusify your answer.

13. Write the full forms of the following:


i. DDL . DML
Informatics Practices
My SQL Worksheet-5
(DML- UPDATE and DELETE commands)
1. What is the purpose of DROP TABLE Command in SOL? How is it different from DELETE command?

2. In a database there are two tables "Product" as shown below:


Table : PRODUCT
P_ ID ProductName Manufacture Price
POO1 Moisturiser XYZ 40
PO02 Sanitizer LAC 35

PO03 Bath Soap COP 25


P004 Shampoo TAP 95
P005 Lens Solution COP 350
Write the command To increase the Price of all the Products by 20.
3 Write the UPDATE Command to change "Sharma" to "Singh" in the LastName" column in the Employee
table.

4. What is the use of UPDATE statement in SQL ? How is it different from ALTER statement?

5 Consider the following table named "GYM"


Table GYM:

ICODE INAME PRICE BRANDNAME

GIO1 Power Fit Exerciser 20000 Power Gymea


GI02 Aquafit Hand Grip 1800 Reliable
GI03 |Cycle Bike 14000 Ecobike
GI04 Protoner Extreme Gym 30000 Coscore

GI05 Message Belt 5000 MessagExpert


GI06 |Cross Trainer 13000 GTCFitness
Write command To change the Brandname to "Fit Trend India" of the item, whose ICODE as "G101 ".

6. Write the UPDATE statement in MySQL to increase commission by 100.00 in the "Commission" column
in the 'Emp' table.

|7. Write two examples of DML commands of SQL.

8. In a database there are two tables 'CD' and TYPE' as shown below :
Table: CD Table:TYPE
CODE TITLE DURATION SINGER CATEGORY
CATEGORY DESCRIPTION
101 Sufi Songs 50 min Zakir Faiz 12
1 Jazz
102 Eureka 45 min Shyama Mukherjee 12
103 Nagmey 23 min Sonvi Kumar 77 12 Classical
104| Dosti 35 min Bobby 1 40 Country Side
78 Pop
Write SQL statement to change the name of Singer "Sonvi Kumar" to "Sonvi Mehra" in all the places
wherever it occurs in CD table.

9 Consider the following table named "GARMENT".


Table : GARMENT

GCODEGNAME SIZE COLOUR PRICE

111 TShirt XL Red 1400.00


112 Jeans L Blue 1600.00
113 Skirt M Black 1100.00
114 Ladies Jacket XL Blue 4000.00

115 Trousers Brown 1500.00


116 Ladies Top Pink 1200.00

1) Write command To change the colour of garment with code as 116 to "Orange".
2) Write command to increase the price of all XL garments by 10%
3) Write command to delete the record with GCode "116"

10. In a Database, there are two tables given below:


Table : EMPLOYEE
EMPLOYEEID NAME SALES JOBID
El SAMIT SINHA 1100000 102
E2 VIJAY SINGH TOMAR 1300000 101
E3 AJAY RAJPAL 1400000 103
E4 MOHIT RAMNANI 1250000 102
E5 SHAILJA SINGH 1450000 103
Table : JOB
JOBID JOBTITLE SALARY
101 President 200000

102 Vice President 125000


103 Administration Assistant 80000

104 Accounting Manager 70000


105 Accoutant 65000
106 Sales Manager 80000

Write SQL command to change the JOBID to 104 of the Employee with ID as E4 in the table 'EMPLOYEE.

11. In Marks column of 'Student' table, for Rollnumber 2, the Class Teacher entered the marks as 45.
However there was a totaling error and the student has got her marks increased by 5. Which MySQL
command should she use to change the marks in 'Student' table.

12. Chhavi has created a table named Orders, she has been asked to increase the value of a column named
salesamount by 20. She has written the following query for the same.
10
10. In a Database, there are two tables given below
Table : EMPLOYEE
EMPLOYEEID NAME SALES JOBID
SAMIT SINHA 1100000 102
E2 VIJAY SINGH TOMAR 1300000 101
E3 AJAY RAJPAL 1400000 103
E4 MOHIT RAMNANI 1250000 102
E5 SHAILJA SINGH 1450000 103
Table: JOB
JOBID JOBTITLE SALARY
101 President 200000

102 Vice President 125000


J03 Administration Assistant 80000

I04 Accounting Manager 70000


105 Accountant 65000
106 Sales Manager 80000

Write SQL command to change the JOBID to 104 of the Employee with ID as E4 in the table EMPLOYEE'

11. In Marks column of 'Student' table, for Rollnumber 2, the Class Teacher entered the marks as 45.
However there was a totaling error and the student has got her marks increased by 5. Which MySQL
command should she use to change the marks in 'Student' table.

12. Chhavi has created a table named Orders, she has been asked to increase the value ofa column named
salesamount by 20. She has written the following query for the same.
10

Alter table Orders Add salesamount =salesamount+20;


Is it the correct query? Justify.

13. Consider the following table:


Table: PharmaDB
RxID Drug DrugName Price PharmacyPharmacyLocation
ID Name
R1000 5476 Amlodipine 100.00 Rx Pitampura, Delhi
Pharmacy
R1001 2345 Paracetamol 15.00 Raj Babadurgarh.
Medicos Haryana
R1002 1236 Nebistar 60.00 MyChemi Rajouri Garden,
st Delhi
RI003 6512 VitaPlus 150.00 MyChemi Gurgaon.Haryana
st
R1004 5631 Levocitrezine 110.00 RxPhama South
cy Extension. Delhi
Write commands in SQL to increase the price of "Amlodipine" by 50.
My SQL Worksheet-6
(DML - SELECT Command)
1. Pooja, a students of class XI, created a table "Book". Price is a column of this table. To find the detai
books whose prices have not been entered she wrote the following query:
Select * from Book where Price = NULL;

2 The LastName column of a table "Directory" is given below:


LastName Based on this information, find the output of the following queries:
Batra a) SELECT lastname FROM Directory WHERE lastname like"_a%";
Sehgal
Bhatia
b)SELECT lastname FROM Directory WHERE lastname not like "%a";
Sharma
Mehta

3. Consider the table TEACHER given below. Write commands in SQL for (1) to (3) and outputf
ID Name Department Hiredate Category Gender Salary
1 Tanya Nanda SocialStudies 1994-03-17 TGT 25000
2 Saurabh Sharma Art 1990-02-12 PRT M 20000
Nandita Arora English 1980-05-16 PGT 30000
James Jacob English 1989-10-16 TGT M 25000
Jaspreet Kaur Hindi 1990-08-01 PRT 22000
Disha Sehgal Math 1980-03-17 PRT F 21000
7 Siddharth Kapoor Science 1994-09-02 TGT M 27000
8 Sonali Mukherjee Math 1980-11-17 TGT F 24500

i. To display all information about teachers of PGT category.


i. To list the names of female teachers of Hindi department.
ii. To list names, departments and date of hiring of all the teachers in ascending order of date of joir
iv. SELECT DISTINCT(category) FROM teacher;

4. The Item_No and Cost columna of a table "ITEMS" are given below:
IITEM NO COST Based on this information, find the output of the following queries:
101 5000
a) SELECT COST +100 FROM ITEMS WHERE ITEM_NO > 103;
102 NULL
103 4000
104 6000
105 NULL

5. Consider the table Projects given below. Write commands in SOL for i) to ii) and output for iv)
PROJECTS
ID ProjName ProjSize StartDate EndDate Cost
1 Payroll-MMS Medium 2006-03-17 2006-09-16 60000
2 Payrol-ITC Large 2008-02-12 2008-01-11 500000
3 IDMgmt-LITL Large 2008-06-13 2009-05-21 300000
4 Recruit-LITL Medium 2008-03-18 2008-06-01 50000
6 IDMgmt-MTC Small 2007-01-15 2007-01-29 20000
5 Recruit-ITC Medium 2007-03-01 2007-06-28 50000
i. To display all information about projects of"Medium" ProjSize
i. To list the ProjSize of projects whose ProjName ends with LITL.
ii. To list ID, Name, Size, and Cost of all the projects in descending order of StartDate.
iv. SELECT DISTINCT ProjSize FROM projects

6. The Mname Column of a table Members is given below :


Mname Based on the information, find the output of the following queries:
() Select Mname from members where mname like "%v";
Aakash (i) Select Mname from members where mname like "%e%";
Hirav
Vinayak
Sheetal
Rajeev
7. Sarthya, a student of class XI, created a table "RESULT". Grade is one of the column of this table. To
the details of students whose Grades have not been entered, he wrote the following MySql query, wh
did not give the desired result.
SELECT * FROM Result WHERE Grade= "Null"
Help Sarthya to run the query by removing the errors from the query and write the correct Query.

8. Consider the table RESULT given below. Write commands in MySql for () to (ii)
Table : Result
No Name Stipend Subject Average Division
() To list the names of those students, who
- Sharon 400 English 38 THIRD have obtained Division as FIRST in the
2 Amal 680 Mathematics 72 FIRST ascending order of NAME.
Vedant 500 Accounts 67 FIRST () To display a report listing NAME, SUB
4 Shakeer 200 Informatics 55 SECOND and Annual stipend received assuming tha
Anandha 400 History 85 FIRST stipend column has monthly stipend.
6 Upasna 550 Geography 45 THIRD

Mr. Janak is using a table with following columns:


Name, Class, Course_ld, Course_name
He needs to display names of students, who have not been assigned any stream or have been assi
Course_name that ends with "economics". He wrote the following command, which did not give
desired result.
SELECT Name, Class FROM Students WHERE Course name = NULL OR Course name="%economics'
Help Mr. Janak to run the query by removing the error and write the correct query.

10 Consider the Table SHOPPE given below. Write command in MySql for () to (ii)
Table SHOPPE
Code Item Company Qty City Price
() To display names of the items whose name s
102 Biscuit Hide & Seek 100 Delhi 10.00 with C' in ascending order of Price.
103 Jam Kissan 110 Kolkata25.00 (i) To display Code, Item name and City of
101 Coffee Nestle 200 Kolkata 55.00 products whose quantity is less than 100.
106 Sauce Maggi 56 Mumbai55.00
107 Cake Britannia 72 Delhi 10.00
104 Maggi Nestle 150 Mumbai10.00
105 Chocolate Cadbury 170 Delhi 25.00
11. What is used in the SELECT clause to return all the columns in the table?

12. In MySQL, Sumit and Fauzia are getting the following outputs of ItemCodes for SELECT statements
used by them on a table named ITEM.(Both have used the SELECT statements on the same table ITEM).
Sumit's Output Fauzia's Output
101 101
102 102
101 105
105 107
101
107

Which extra keyword has Fauzia used with SELECT statement to get the above output?

13. Consider the table 'PERSONS' given below. Write commands in SQL for () to (iv) and write output for ().
Table : PERSONS

Pld Surname Firstname Gender City PinCode BasieSalary () Display the SurNames, FirstNames and
Sharma Geeta Udhamwara 182141 50000 Cities of people residing in Udhamwara
Singh Surinder Kupwara 183222 75000
city.
Narar (i) Display the Person Ids (PID), cities and
Jacob Peter M Bhawani 185155 45000 Pincodes of persons in descending order
Alvis Thomas M Ahmed 380025 50000
of Pincodes.
Nagar
(ii) Display the First Names and cities of
Mohan Garima M Nagar 390026 33000
all the females getting Basic salaries
Coolangatta
above 40000.
Azmi Simi New Delhi 110021 40000
Kaur ManproetF Udhamwara 182141 42000
(iv) Display First Names and Basic Salaries
of all the persons whose firstnames star
with "G"
(v) SELECT Surname FROM Persons Where BasicSalary>=50000;

14. Mr. Tondon is using table EMP with the following columns.
ECODE,DEPT,ENAME,SALARY
He wants to display all information of employees (from EMP table) in ascending order of ENAME and
within it in ascending order of DEPT. He wrote the following command, which did not show the desired
output.
SELECT * FROM EMP ORDER BY NAME DESC,DEPT;
Rewrite the above query to get the desired output.

15. Consider the following table named "GYM" with details about fitness items being sold in the store. Write
command of SQL for (i) to (i).
Table GYM:
1CODE INAME PRICE BRANDNAME
) To display the names of all the items whose name starts
GIOt Power Fit Exerciser 20000 Power Gymea
with "A".
GI02 Aquafit Hand Grip 1800 Reliable
14000 Ecobike
() To display ICODES and INAMES of all items, whose
GIO3 Cycle Bike
Brandname is Reliable or Coscore.
GIO4 Protoner Extreme Gym 30000 |Coscore
GI05 Message Belt 5000 MessagEpert
GI06 lCross Trainer 13000 GTCFitness
|4
16. Consider the following table named 'SBOP" with details of account holders. Write commands of MySql
forTable(i): SBOP
to (i) and output for (ii).
Accountao Name Balance DateOtopen Tranaton
() To display Accountno, Name and DateOfopen of account
15000.o0 2011-02-24 holders having transactions more than 8.
SB-2 Nr.Aait 23567.a9
() To display al information of account holders whose
transaction value is not mentioned.
45000.00 2012-02-04
S8-3 E.Sakahi
(ii) SELECT NAME,BALANCE FROM SBOP WHERE NAME LIKE
S3-4 .Gopal 23812.35 2013-09-22 "%i":

S-5 Dennis 43459.80 2009-11-10 s

17. When using the LIKE clause, which wildcard symbol represents any sequence of none, one or more
characters ?

18. Consider the table FLIGHT given below. Write commands in SQL for () to (iv) and output for ().
Table: FLIGHT
FLCODE START DESTINATION NO _STOPS NO_ FLIGHTS
IC101 DELHI AGARTALA 1 5
IC102 MUMBAI SIKKIM 1
IC103 DELIHI JAIPUR 7
IC105 KANPUR CIIENNAI 2
IC107 MUMBAI KANIPUR 0
IC431 INDORE CHENNAI 3 2
IC121 DELII AIIMEDABAD 2 6

() Display details of all flights starting from Delhi.


(i) Display details of flights that have more than 4 number of flights operating.
(i) Display flight codes, starting place, destination, number of flights in descending order of number of
flights.
(iv) Display destinations along with flight codes of all the destinations starting with 'A'.
(v) SELECT DISTINCT(NO_STOPS) FROM FLIGHT;

19. What will be the output of the following queries on the basis of Employee table:
+

| Empld|EName |Salary () Select Salary+100 from Employee where Empld='AO02;


|A001 | Bob | 5600 |
| A002 | John | NULL |
| A003 |Tom 5000 |

20. Pranay, who is an Indian, created


5_No Name Age City Country Email_id a table named "Friends" to store
1 TAlice |14 Washington USA [email protected] his friend's detail.
2 Charles 12 |Copenhagen Denmark [email protected] Table "Friends" is shown below.
3 |Angel 16 |Chicago USA [email protected]
4 Jasmine 15 Sydney Australia [email protected] Write commands in SQL for () to
5 Raj 14 New Delhí India [email protected] (iii) and output for (iv).
6 Jette 13 Nykobing Denmark [email protected]
7 Alexender 15 Melbourne Australia NULL
Shashank 16 Banglore |India NULL
15
i. To display list of all foreigner friends.
ii. To list name, city and country in descending order of age.
iii. To list name and city of those friends who don't have an email id.
iv. Select name,country from friends where age>12 and name like 'A%;

21. Consider the following table named "GARMENT".Write command of SQL for ()
to (iv) and output for (v) to (vi).
Table : GARMENT () To display names of those garments that
GCODE GNAME SIZE COLOUR PRICE are available in 'XL' size.
111 TShirt XL Red 1400.00 (i) To display codes and names of those garments
112 Jeans Bl ue 1600.00
that have their names starting with 'Ladies'.
113 Skirt M
(ii) To display garment names, codes and prices of
Black 1100.00
those garments that have
114 Ladies Jacket XL Blue 4000.00 price in the range 1000.00 to 1500.00 (both
115 Trousers L Brown 1500.00 1000.00 and 1500.00 included).
116 Ladies Top Pink 1200.00
(iv) SELECT GNAME FROM GARMENT WHERE
SIZE IN (M, L) AND PRICE> 1500;

22. Consider the table 'empsalary'


ID Salary
To select tuples with some salary ,Siddharth has written the following erroneous
101 43000 SQL
102 NULL
statement:
SELECT ID, Salary FROM empsalary WHERE Salary =something;
104 56000

107 NULL

23. Consider the table 'Employee'.


Nama Location
Write the sQL command to obtain the following output :
Gurpreet Mumbai Location

Jatinder Chennal
Mumbai
Deepa Mumbal
Chennai
Harsh Chennal

Simt New Detht New Delhi


Anita Bengaluru
Bengaluru

24. NAME AGE ADDRESS SALARYPHONE


Table "Emp" is shown below. Write commands in
Siddharth 25 A-4, Ashok Vihar, Dehi62000 98110766656
1

2 Chavt 21 B-21, Model Town, 71000 99113423989


SQL for () to (ii) and output for (iv) and (v)
Mumbal and (vi)
i. To display list of allemployees below 25 years
Karan 26 KC-24, North Avenue,
Bhooal
65000 8105393578 old.
Raunaq |22 A152, Gomti Nagar, 89000 99101393576
16
5 Kunal |27 B5/45, Uday Park, 80000 97653455654

ii. To list names and respective salaries in descending order of salary.


ii. To list names and addresses of those persons who have 'Delhi' in their address.
iv. SELECT Name, Salary FROM Emp where salary between 50000 and 70000;
v. SELECT Name, phone from emp where phone like 99%;
25. Mrs. Sen entered the following SQL statement to display all Salespersons of the cities "Chennai"
and 'Mumbai from the table 'Sales'.
Scode Name City SELECT FROM Sales WHERE
101 Aakriti Mumbai City='Chennai AND City='Mumbai';
102 Aman Chennai
103 Banit Delhi
104 Fauzia Mumbai

Rewrite the correct statement, if wrong or write statement is correct.

26. Write commands in SQL for (0) to (ii) and output for (iv).
Table : Store
Storeld Name City
Location NoOfEmployees Datepened| SalesAmount
S101 Planetfashion KarolBagh Delhi 7 2015-10-16 300000
S102 Trends Nehru Mumbai 11 2015-08-09 400000
Nagar
S103 Vogue Vikas Delhi 10 2015-06-27 200000
Vihar
S104 Superfashion Defence Delhi 8 2015-02-18 450000
Colony
S105 Rage Bandra Mumbai 5 2015-09-22 600000
() To display name, Iocation, city, SalesAmount of stores in descending order of SalesAmount.
(i) To display names of stores along with SalesAmount of those stores that have fashion' anywhere in
their store names.
(ii) To display Stores names, Location and Date Opened of stores that were opened before 1st March,
2015.
(iv) SELECT distinct city FROM store;

27. Which clause would you use with Select to achieve the following:
i.To select the values that match with any value in a list of specified values.
ii.Used to display unrepeated values of a column from a table.

RxlD Drug DugNaue Pice Pharmacy PuamacyLocaton


28.
Name
Consider the following table:
RI0005476 Amlodipine 100.00 Rx Pitampura, Delli Table: PharmaDB
Pharmacy Write commands in SQL for ) to (ii) and output
RI001 2345 Paracetamol 15.00 Raj Balbadurgarh
Medicos Haryana
for (iv):
RI002 1236 Nebistar 60,00 MyClhemi Rajouri Garden., i. To increase the price of "Amlodipine" by 50.
st Delhi
RI0036512 VitaPlus I50.00 MyChemi Grgaon.Haryana 17
st

ii. To display all those medicines whose price is in the range 100 to 150.
ii. To display the Drug ID, DrugName and Pharmacy Name of all the records in descending order of their
price.
iv. SELECT RxlD, DrugName, Price from PharmaDB where PharmacyName IN ("Rx Parmacy", "Raj
Medicos"):

29. Write SQL statement that gives the same output as the following SQL statement but uses 'IN' keyword.
SELECT NAME FROM STUDENT WHERE STATE = VA':

30. Which one of the following SQL queries will display all Employee records containing the word "Amit",
regardless of case (whether it was stored as AMIT, Amit, or amit etc.) ?
() SELECT* from Employees WHERE EmpName like UPPER'%AMIT%;
(ii) SELECT *from Employees WHERE EmpName like %AMIT% or "%AMIT% OR '%amit%;
(ii) SELECT *from Employees WHERE UPPER (EmpName) like "%AMIT%;

You might also like