Assignments - MySQL
1 . Rajan created a table named Item, he wants to see those Items whose price is between
200 and 800. He wrote a query-
SELECT * FROM Item WHOSE price>200 OR <800
Help Rajan to run the query by removing the errors from the query
and rewriting it.
2 . How do we restrict duplicate rows in SQL SELECT Query? Give
example (1)
3 . Mr. Scott has created a table namely SAMPLE that has 6 columns and
3 records, (1)
after testing, Scott added two more columns, and ten more records
but deleted one
column and three records. What is the degree and cardinality of
the table now?
4 . Write the SQL commands for ( a) to (f) and write the output of the
(g) on the basis
of the table.
TABLE : BANK
Acc_N Acc_nam Bname Amoun Dateofop Type_acc
o e t en
15672 Karan Bank of 15000 12/01/20 NRE
Baroda 08
24309 Puneet State Bank 25000 01/02/20 FIXED
07
36090 Anirban Oriental Bank 17000 15/07/20 NRE
09
42111 Yatin Bank of 38000 10/02/20
Baroda 09
50089 Sunny State Bank 47000 06/02/20 NRE
08
64523 Jayant ICICI Bank 34000 10/08/20 SAVING
08
85198 Tarun Oriental Bank 22000 04/04/20 SAVING
10
90050 Jisha ICICI Bank 75000 05/01/20 SAVING
07
Anil Oriental Bank 70000 09/09/20
65421
08
a. Display the details of all account holders of State Bank whose amount is
more than 50000.
b. Display the Account holder name, Bank name and Amount of all FIXED
and NRE accounts.
c. Add a new account with the following details :
80908 , Robert , ICICI Bank , 50000 , 23/12/2011 , FIXED
d. Give the output of the following SQL commands :
e. Select distinct Bname from BANK;
f. Select Acc_no, Acc_name, Bname from BANK
where Bname =’Bank of Baroda’ or Bname =’ Oriental
Bank’ ;
g. Select Acc_name, Amount from BANK
where dateofopen >’01/01/2009’
5. Consider the table ‘Employee’.
Employee Name Location
Gurpreet Mumbai
Jatinder Chennai
Deepa Mumbai
Harsh Chennai
Simi New Delhi
Anita Bengaluru
Write the SQL command to obtain the following output :
Location
Mumbai
Chennai
New Delhi
Bengaluru
6. An attribute A of datatype varchar (25) has the value “Amit”. The attribute B of datatype
Char (25) has the value “Karanita”. How many characters are occupied in attribute A?
How many characters are occupied in attribute B?
7. Write the SQL commands for (i) to (vi) and write the output for (vii) based on the table
CUSTOMS
ITEMC NAM TYPE COS DATEOFIMP CUST_D
ODE
E001 ET.V ELECTRONIC 2300 T ORT
09/10/2012 UTY
875
E006 VCR S
ELECTRONIC 0
1950 12/06/2013 550
G007 SHIRT S
GARMENTS 0
5600 25/09/2012 250
S010 PEPPER SPICES 8500 30/07/2012 345
S008 CARDAM SPICES 9700 17/04/2013 555
C004 AM
PERFUME COSMETICS 800 28/05/2014 600
G003 JEANS GARMENTS 6000 15/11/2013 120
C006 CREAM COSMETICS 600 20/12/2012
i) To show all information about the electronic items.
ii) To list itemcode, name, cost, cust_duty of item its cost less than 1000 and greater than 8250
iii) Display the details of spices and cosmetics from customs.
iv) Insert a new row with the following information:
E009, COMPUTER, ELECTRONICS, 6700, 30/09/2013, 900
v) To display the different types of items
vi) Give the output of the following SQL Statements:-
a. Select NAME from customs where TYPE=”GARMENTS”;
b. Select ITEM CODE, NAME,TYPE from customs
where DATEOFIMPORT>=’01/10/2013’
c . Select NAME, COST from customs where TYPE<> ‘ELECTRONICS’ ;
8 . In a database there is a table Cabinet. The data entry operator is not able to put NULL
in a column( Name ) of Cabinet. What may be the possible reason(s)?
9. TABLE BUS
Column name Data type Size Constraint
B_NO Integer 4 PRIMARY KEY
B_ORIGIN VARCHAR 15 NOT NULL
B_DEST VARCHAR 15 NOT NULL
B_TIME Decimal 5,2
B_CAP Integer 3 Not greater than 1000
i) Write the MySQL command to create the above table BUS with constraints.
ii) Write the MySQL command to add a new row to the table BUS.
10. If a database “Library” exists, which MySql command helps you to start working in that database?
11. Write SQL command to create the table Passenger with given constraint.
Table: Passenger
Column Name Data Type & Size Constraint
P_Number Char(20) Primary Key
P_Name Varchar (20) Not null
Source Varchar(20)
Destination Varchar(20)
Charges Float(7,2) Between 2000 - 5000
Age Number Not Null
12. Consider table BOOKS given below. Write commands in SQL for table BOOKS
BOOK_ID BNAME AUTHOR PUBLISHER PRICE TYPE
F0001 The Tears William Hopkins First publ. 750 Fiction
F0002 Thunderbolts Roberts EPB Fiction
T0001 My first C++ Brooke First Publ. 250 Text
T0002 C++ Brainworks Rossaine TDH 325 Text
C001 Fast Cook Kapoor EPB 350 Cookery
i. To show Book name, Author name and Price of Fiction books of EPB publisher.
ii. To display details of C++ books.
iii. To display the price of all books of First Pub.
Write the output of the following
vi. Select (Distinct Type) From Books;
vii. Select bname From Books Where Type<>’Text’;
ID Name Department Hiredate Category Gender Salary
1 Tanya Nanda SocialStudies 1994-03-17 TGT F 25000
2 Saurabh Sharma Arts 2000-02-12 PRT M 20000
3 Nandita Arora English 2003-05-16 PGT F 30000
4 James Jacob English 2009-10-16 TGT M 25000
5 Jaspreet Kaur Hindi 1998-08-01 PRT F 22000
6 Disha Sehgal Math 2010-03-17 F 21000
7 Sid Kapoor Science 2019-09-02 TGT M 27000
8 Sona Mukherjee Math 2001-11-17 F 24500
13. Consider table TEACHER given below. Write commands in SQL for (i) to (vi) and
output for (v) to (viii)
TEACHER
i. To display all information about female teachers of PGT category.
ii. To list name, department, salary of male teachers
iii. To list name, department and hire date of all the teachers
iv. To display the details all teachers of the Maths Department getting salary less than 25000.
v. Insert a new record into table Teacher with your own data values.
vi. To display the details all teachers.
vii. To display different departments of the table.
14. Observe the following table (examresult) structure and determine the appropriate data type
and constraints for the table as per the given specification then write a query to create a table:
Field name Data Type Constraint
rollno Store 4 digit number Unique and Not empty
sname Store name of 20 characters Not empty
marks Store marks with 2 decimal places Default 0
grade Store grades with two characters
15. Categorize the following commands into DDL and DML:
SELECT, ALTER, INSERT, DROP
16. Observe this table courses and write answers for below-given questions:
CourseID CourseName Fees
C0001 Python for Beginners 15000
C0002 Python Advanced 18000
C0003 Core Java 12000
C0004 Advanced Java 15000
C0005 Website Development 12000
a) Suggest a suitable data type for all the columns.
b) Write SQL command to insert a new record: C0006, WordPress CMS, 10000.
a) Display course details of Core Java and Advance Java.
b) Display courseID , CourseName for courses whose fees are less than 15000.