(i) Create a table CUSTOMER with following details:
Column Name Data Type
CustNo Varchar(5)
Name Char(20)
Address Char(50)
(ii) Consider the following table SummerCamp and write the queries (a) and (b).
Table: SummerCamp
First Last
Child ID DOB Gender Group
Name Name
109 Vedansh Gupta 30/06/10 M 2A
214 Mack Tyagi 09/12/08 M 1B
115 Aditi Thakur 13/04/09 F 1A
Chauha
108 Vikrant 02/02/09 M 2A
n
141 Swati Saini 06/05/10 F 2B
233 Vishakha Tyagi 01/08/10 F 3A
274 Madhur Gupta 06/03/10 M 3B
(a) Write a command to insert a new record with the following values:
(105, ‘Shyam’, ‘Sharma’, 07/09/10, ‘M’, ‘1A’)
(b) Write a query to display all the record of table SummerCamp whose DOB between 02/02/09 and
06/03/10.
Answer:
(i) CREATE TABLE CUSTOMER (CustNo Varchar(5), Name Char(20), Address Char(50));
(ii) (a) INSERT INTO SummerCamp VALUES (105, ‘Shyam’, ‘Sharma’, 07/09/10, ‘M’, ‘1 A’);
(b) SELECT * FROM SummerCamp WHERE DOB BETWEEN 02/02/09 AND 06/03/10;
2. i) Create a table SHOP with the following fields:
Column Name Data Type
Code Varchar(5)
Name Char(50)
Type Varchar(3)
Cost Int
Margin Float
Qty Int
(ii) Consider the following table EmployeeSalary and write the queries (a) and (b).
Table: Employee Salary
LastName FirstName Dept PayrollNumber Salary (?) Job Title
Shen James Finance A621 19500 Payroll Clerk
Gupta Shruthi Finance M502 35000 Accountant
Bedi Reeta Fluman Resource M421 18500 Secretary
Walker Tia Sales W815 24000 Sales Represen-tative
Shafia Ahmed Factory H219 39000 Factory Manager
Mittal Chavi Purchasing M134 20000 Purchasing Clerk
(a) Write a command to update the salary of the employee to 25000, whose job title is secretary.
(b) List all data of table EmployeeSalary.
Answer:
(i) CREATE TABLE SHOP (Code Varchar(5), Name Char(50), Type Varchar(3), Cost Int,
Margin Float, Qty Int);
(ii) (a) UPDATE EmployeeSalary SET Salary = 25000 WHERE JobTitle = ‘Secretary’;
(b) SELECT * FROM EmployeeSalary;
3. (i) The structure of a table “ITEM” is given below. Suggest suitable data type and size of each column.
Column Name Data Type Size
Itemno …….. …………
Iname …….. …………
Price …….. …………
Quantity …….. …………
(ii) Consider the following table “ITEM”.
Itemno Iname Price Quantity
11 Soap 40 80
22 Powder 80 80
33 Face Cream 250 25
44 Shampoo 120 100
55 Soap Box 20 50
Write queries to
(a) Display the total amount of each item. The amount must be calculated as the Price multiplied by
Quantity for each item.
(b) Display the details of items whose Price is less than 50.
Answer:
Column Name Data Type Size
Itemno Integer 2
Iname Varchar 15
Price Integer 3
Quantity Integer 3
4. i) Create the table SummerCamp with the following fields:
Column Name Data Type
ChildID Varchar(5)
FirstName Char(20)
LastName Char(20)
DOB Date
Gender Char(2)
Group Varchar(5)
(ii) Consider the following table APPLICANTS and write the queries (a) and (b).
TABLE:APPLICANTS
No. NAME FEE GENDER C_ID JOINYEAR
1012 Amandeep 30000 M A01 2012
1102 Avisha 25000 F A02 2009
1103 Ekant 30000 M A02 2011
1049 Arun 30000 M A03 2009
1025 Amber 40000 M A02 2011
(a) To display NAME, FEE, GENDER, JOINYEAR about the APPLICANTS, who have joined before 2010.
(b) To display the names of all applicants in ascending order of their JOINYEAR.
Answer:
5. i) Create the table SHOP with the following fields:
Column Name Data Type
S_No Varchar(5)
P_Name Char(20)
S_Name Char(20)
Qty Int
Cost Float
City Char(20)
(ii) Consider the following table CUSTOMER and write the queries (a) and (b).
CID CNAME GENDER SID AREA
1001 R SHARMA FEMALE 101 NORTH
1002 M R TIWARY MALE 102 SOUTH
1003 M K KHAN MALE 103 EAST
1004 A K SINGH MALE 102 EAST
1005 S SEN FEMALE 101 WEST
1006 R DUBEY MALE 104 NORTH
(a) To display CNAME, AREA of all female customers from CUSTOMER table.
(b) To display the details of all the CUSTOMER in ascending order of CNAME
within SID.
Answer:
[1] 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 Description Constraint Description
rollno Store 4 digit unique numbers Unique and Not empty
sname Store name of 20 characters long Not empty
marks Store marks with 2 decimal places Default 0
grade Store grades with two characters
[2] Aman is working in a multinational company. He wants to maintain records of employees in the
database and create a database to keep a track of all the records. Help him to write the following
commands:
i) Create a table emp with the following structure:
Field Data Type Constraint
empno int(4) Primary Key
ename varchar(20) Not Null
designation varchar(20)
Salary decimal(7,2)
doj date
deptno int(2)
ii) Write SQL command to insert a record of your choice
iii) Write SQL command to add new column comm with int datatype.
[3] Observe the following table student and write answers for the below-given queries:
rollno name stream percentage class
1201 Krish Commerce 85.79 12D
1202 Jay Science 89.71 12B
1203 Nadiya Commerce 92.74 12C
1204 Archi Science 72.84 12A
1205 Adnan Commerce 84.86 12D
1206 Mahek Science 62.11 12B
i) Display the student’s details of the commerce stream.
ii) Display records of class 12D and 12B students
iii) Change the percentage of Mahek to 64.15.
iv) Delete records of those who secured less than 60%.
[4] Consider the following table – candidate and write queries given below:
Sno name fees subject marks status
1 Preet 350 PCM 68 pending
2 Vansh 450 PCB 52 pending
3 Dhwanil 350 PCM 89 admitted
4 Kirsha 450 PCM 75 pending
5 Diya 350 PCB 72 admitted
i) Display the candidates for PCM subject
ii) Display names of candidates whose admission is pending in ascending order of name.
iii) Display the records of PCB candidates whose marks are less than 70.
iv) Display the name, fees and subject of candidates whose fees are more than 400.
[6] Consider the following table teacher and write the given queries below:
Teacher_ID Name Age Subject DOJ Salary Gender
101 Kamlesh Mali 55 Physics 1991/04/01 75000 M
102 Praveen Singh 48 Maths 1998/06/01 65000 M
103 Hemisha Patel 45 Gujarati 2000/02/07 55000 F
104 Alauddin Sayed 41 Computer Science 2008/04/02 52000 M
105 Dipti Agrawal 38 Maths 2012/04/01 48000 F
106 Krunali Prajapati 37 Computer Science 2016/04/01 44000 F
i) Display the information of Maths and Computer Science subject teachers
ii) Display the information of teachers who are getting salaries in the range of 45000 to 75000
iii) Display the information of teachers whose age are more than 45 years
iv) Display the name of teachers along with a report on how many years remain for their retirement
[7] Observe the table store and write queries given below:
itemno itemname supplier qty rate city state
1001 Chocolate Cadbury India 150 40.00 Pune Maharashtra
1002 Bread Amul 500 30.00 Anand Gujarat
1003 Cookies Dark Fantasy 250 35.00 Haridwar Uttarakhand
1004 Biscuits Parle 700 25.00 Jaipur Rajasthan
1005 Namkeen Gopal 500 45.00 Rajkot Gujarat
1006 Sev Bikaji 600 32.00 Bikaner Rajasthan
1007 Chocolate Amul 500 42.00 Anand Gujarat
i) Display the records in the descending order of rate
ii) Display the itemname, supplier from Gujarat and Rajasthan.
iii) Delete a column city
iv) Display the information of items whose price is more than 30 and the supplier is Amul.
[8] Observe the following table team and write queries given below:
Name Department jobid salary post
Mahesh House Keeping H45 28000 Peon
Nitigna Admin A11 32000 Receptionist
Nikita Admin A02 38000 Secretary
Ankit HR HR01 50000 HR Head
Yogesh Management M003 42000 Manager
Vikas HR HR03 34000 HR Manager
Dinesh HR HR02 39000 HR HOD
i) Display the information whose name ends with sh.
ii) Identify the primary key and justify your answer.
iii) Display name, department, and salary of an HR department.
iv) Display the information with a 5% of increment in salary for admin department team members.
Ans.:
i) select * from team where name like ‘%sh’;
ii) The jobid field can be a primary key as it contains unique records. Jobid for each team member is
unique.
iii) select name, department, salary from team where department =’HR’;
iv) select salary+(salary*0.5) from team where department=’Admin’;
Ans.:
i) select * from store order by rate desc;
ii) select itemname, supplier from store where state in (‘Gujarat’,’Rajasthan’);
iii) alter table store drop column city;
iv) select * from store where rate > 30 and supplier = ‘Amul’;
Ans.:
i) select * from teacher where subject = ‘Maths’ or Subject = ‘Computer Science’;
OR
select * from teacher where subject in( ‘Maths’, ‘Computer Science’);
ii) select * from teacher where salary between 45000 and 75000;
OR
select * from teacher where salary >=45000 and salary<=75000;
iii) select * from teacher where age>45;
iv) select name, 60-age “Year of retirement” from teacher;
Ans.:
i) select name from candidate where subject=’PCM’;
ii) select name from candidate where status=’pending’ oder by name;
iii) select * from candidate where subject =’PCB’ and marks < 70;
iv) select name,fees, subject from candidate where fees > 400;
Ans.:
i) select * from student where stream=’commerce’;
ii) select * from student where class in(’12B’,’12D’)
or
select * from student where class =’12B’ or class=’12D’;
iii) update percentage=64.15 where name=’Mahek’;
iv) delete from student where percentage<60;
Ans.:
i)
create table emp
(empno int(4) primary key,
ename varchar(20) not null,
designation varchar(20),
salary decimal(7,2),
doj date,
deptno int(2));
ii) insert into emp values
(1324, ‘Divyesh’, ‘President’, 25000, ‘2018/02/04’, 20);
iii) alter table emp add column comm int(5);
Ans.:
1. Rollno – int(4) – Primary Key
2. Sname – Varchar(20) – Not Null
3. Marks – Decimal(5,2) – default 0
4. Grade – Varchar(20)
Create table command:
create table examresult
(rollno int(4) primary key,
sname varchar(20) not null,
marks Decimal(5,2) default 0,
grade varchar(20));