0% found this document useful (0 votes)
5 views4 pages

SQL Assignment of All 4 Chapters

The document outlines assignments related to MySQL SQL commands, covering topics such as SQL command classification, DDL vs DML commands, and various SQL queries for data manipulation. It includes tasks for creating, updating, and deleting records in tables, as well as using functions, group by, and join operations. Additionally, it addresses constraints, aggregate functions, and the differences between SQL commands like drop and delete.

Uploaded by

gamingsmp100
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)
5 views4 pages

SQL Assignment of All 4 Chapters

The document outlines assignments related to MySQL SQL commands, covering topics such as SQL command classification, DDL vs DML commands, and various SQL queries for data manipulation. It includes tasks for creating, updating, and deleting records in tables, as well as using functions, group by, and join operations. Additionally, it addresses constraints, aggregate functions, and the differences between SQL commands like drop and delete.

Uploaded by

gamingsmp100
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/ 4

ASSIGNMENTS CHAPTERWISE

Chapter-5 MySQL SQL Revision Tour

1. How are SQL command classified?


2. Differentiate between DDL and DML commands.
3. Shivansh has Created the following table named exam:
RegNo Name Subject Marks
1 Sanchay Computer Science 98
2 Harshita IP 99
3 Kumkum CS 97
4 Samiksha IP 99
5 Molly IP 95
Help him in writing SQL queries to perform the following tasks:
a. Insert a new record in the table having following Values: [6, 'Khushi', 'Cs', 85].
b. To change the value of IP to Informatics practices in subject column.
c. To remove the record of those students whose marks are less than or equals to 90.
d. To add a new column grade of suitable data type.
e. To display record of Informatics practices subject.
f. To display the name of those students whose name is starting from S
4. Write the SQL commands for the following question on the basis of given table STUDENT.
No Name Stipend Stream AvgMarks Grade Class
1 Sonam 400 Medical 78.5 C 11
2 Parth 500 Commerce 62.7 B 12
3 Jhanvi 300 Commerce 87.6 A 11
4 Shivansh 450 Humanities 98.5 A 11
5 Akshat 350 Nonmedical 72.8 C 12
6 Shabana 450 Medical 68.3 D 12
7 Vaani 400 Humanities 85.5 A 11
8 Bhoomi 650 Commerce 81.6 A 12
9 Ujjawal 500 Medical 94.6 A 11
10 Alok 350 Nonmedical 79.4 C 12
a. Increase the stipend by 35% of those students who are in non-medical stream.
b. Display the name of those students who are in 11th class.
c. Display the average marks of all the students in descending order
d. Display the name of those students who is having "o" in second position and "n" in anywhere in their
name.
e. Display the name from my Stephens and their average marks along with the Great who are getting
stipend more than 400.
5. What are the constraints? write the constraint names along with their usage.
6. Mr Mittal is using a table with the following columns name, class, stream_id, stream_name
He needs to display name of students who have not been assigned any stream or have been assigned
stream name that ends with computers.
SELECT name, class FROM Student
WHERE stream_name = NULL OR stream_name = "%computers";
Help Mr Mittal to run the query by removing the error and right correct query.
7. Sarthak, I student of class 12th created a table called Class. Grade is one of the columns of this table.
To find the details of a student whose grades have not been entered, He wrote the following my SQL
query, which did not give the desired result:
SELECT * FROM Class WHERE grade = "NULL";
Help Sarthak to run the query by removing the error from the query and rewrite the correct query.
8. what is the difference between the drop table command and delete command justify with example.
Chapter-6 MySQL Functions
1. What is a function? also explain their types with their sub functions.
2. What is the difference between sysdate() and now() with example.
3. Which function is used to find the index value of substring from the given String.
4. Answer the following questions:
5. Which of the following is not an aggregate function?
a. Round() b. sum() c. count() d. avg()
6. Which of the following SQL function does not belong to the maths function category?
a. power() b. round() c. length() d. mod()
7. What will be the output of the following query?
SELECT POWER(2, MOD(17,3));
a. 8 b. 1 c. 0 d. 4
8. The count(*) function provide the total number of ____ within a relation (table) in a relational database.
a. Columns b. unique values c. not-null values d. row
9. If the substring is not present in a stringcomma instr() returns:
a. -1 b. 1 c. NULL d. 0
10. Predict the output of the following query:
SELECT LCASE(MONTHNAME ('2023-03-05'));
a. May b. March c. may d. march
11. To remove the leading and trailing space from the data value in a column of MySQL table, we use
a. left() b. right() c. trim() d. ltrim()
12. Write the output of the following SQL command:
SELECT round(49.88);
a. 49.88 b. 49.8 c. 49.0 d. 50
13. Predict the output of the following query:
SELECT mod(9,0);
a. 0, b. NULL c. NaN d. 9
14. what will be the output of the following query?
SELECT substr("G20 2023 INDIA",5,4);
a. G20 2 b. 2023 c. INDI d. 023
15. Write a query to display name, job, salary and HireDate of employees who are hired between May 20,
1990 and December 31, 1991. Order the query in ascending order of HireDate (considered table emp)
16. Write the SQL functions which will perform the following operations
a. To display the name of the month of the current date.
b. To remove spaces from the end of a string, "Panorama"
c. To display the name of the day e.g., Friday or Sunday from your date of birth, dob.
d. To display the starting position of your first name(fname) from your whole name(name).(table-empl)
e. To compute the remainder of division between two numbers, n1 and n2.
f. To display the year from the date of admission which is '2023-05-15'.
17. Write suitable SQL query for the following
a. Display 7 characters extracted from 7th left character onwards from the string 'INDIA SHINING'
b. Display the position of occurrence of string 'COME' in the string 'WELCOME WORLD'
c. Round off the value 23.78 to one decimal place.
d. Display the remainder of 100 divided by 9.
e. Remove all the expected leading and trailing spaces from a column userid of the table'USERS'
Chapter-7 Querying Using SQL: Order by, Group By
1. What use of Group by clause?
2. What is the use of order by clause?
3. What is having clause? How it is different from where clause?
4. What is aggregate function? How it is different from scaler function.
5. Which SQL statement allows you to find the highest price from the table BOOK_INFORMATION?
(a) SELECT BOOK_ID, BOOK TITLE, MAX (PRICE) FROM BOOK INFORMATION;
(b) SELECT MAX(PRICE) FROM BOOK INFORMATION;
(c) SELECT MAXIMUM (PRICE) FROM BOOK INFORMATION;
(d) SELECT PRICE FROM BOOK INFORMATION ORDER BY PRICE DESC;
6. Which SQL statement lets you find the sales amount for each store?
(a) SELECT STORE_ID, SUM (SALES_AMOUNT) FROM SALES;
(b) SELECT STORE_ID, SUM (SALES_AMOUNT) FROM SALES ORDER BY STORE_ID;
(c) SELECT STORE_ID, SUM (SALES_AMOUNT) FROM SALES GROUP BY STORE ID;
(d) SELECT STORE_ID, SUM (SALES_AMOUNT) FROM SALES HAVING UNIQUE STORE_ID;
7. Which SQL statement lets you list all stores whose total sales amount is over 5000?
(a) SELECT STORE_ID, SUM (SALES_AMOUNT) FROM SALES GROUP BY STORE_ID HAVING
SUM(SALES AMOUNT) > 5000;
(b) SELECT STORE_ID, SUM (SALES_AMOUNT) FROM SALES GROUP BY STORE_ID HAVING
SALES AMOUNT > 5000;
(c) SELECT STORE_ID, SUM(SALES AMOUNT) FROM SALES WHERE SUM (SALES_AMOUNT) >
5000 GROUP BY STORE_ID;
(d) SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES WHERE SALES AMOUNT > 5000
GROUP BY STORE_ID;
8. A relation Vehicles is given below:
V_no Type Company Price Qty
AW125 Wagon Maruti 250000 25
T0083 Jeep Mahindra 400000 15
S9090 SUV Mitsubishi 250000 18
M0892 Mini van Datsun 150000 26
W9760 SUV Maruti 250000 18
R2409 Mini van Mahindra 350000 15
Write SQL commands to
(a) Display the average price of each type of vehicle having quantity more than 20.
(b) Count the type of vehicles manufactured by each company.
(c) Display the total price of all the types of vehicles.
Table: Garment
GCODE Description Price FCODE READYDATE
10023 PENCIL SKIRT 1150 F03 19-DEC-08
10001 FORMAL SHIRT 1250 F01 12-JAN-08
10012 INFORMAL SHIRT 1550 F02 06-JUN-08
10024 BABY TOP 750 F03 07-APR-07
10090 TULIP SKIRT 850 F02 31-MAR-07
10019 EVENING GOWN 850 F03 06-JUN-08
10009 INFORMAL PANT 1500 F02 20-OCT-08
10017 FORMAL PANT 1350 F01 09-MAR-08
10020 FROCK 850 F04 09-SEP-07
10089 SLACKS 750 F03 31-OCT-08
a. SELECT SUM (PRICE) FROM GARMENT WHERE FCODE = 'F01' ;
b. SELECT COUNT (DISTINCT PRICE) FROM GARMENT ;
c. SELECT MAX(PRICE) FROM GARMENT GROUP BY FCODE;
d. SELECT SUM(PRICE) AS ‘FABRICPRICE’ FROM GARMENT GROUP BY FCODE HAVING
FABRICPRICE > 2200;
Chapter-8 Join Operations
1. Write SQL queries for the following :
Table: Sales Table: Location
SALESMAN NAME SALES LOCATIONID LOCATIONID LACATIONNAME
S1 ANITA SINGH 25000 102 101 DELHI
S2 Y.P. SINGH 130000 101 102 MUMBAI
S3 TINA JAISWAL 145000 103 103 KOLKATA
S4 GURDEEP SINGH 125000 102 104 CHENNAI
S5 PARNIKA SHARMA 140000 103
a. To display SalesmanID, names of salesmen, LocationID with corresponding location names.
b. To display names of salesmen, sales and corresponding location names who have achieved Sales
more than 1300000.
c. To display names of those salesmen who have 'SINGH' in their names.
d. Identify Primary key in the table SALES. Give reason for your choice.
e. Write SQL command to change the LocationID to 104 of the Salesman with ID as S3 in the table
'SALES'.

2. Write the commands in SQL queries for the following:


Table: Product Table: Client
PID PNAME MANUFACTURE PRICE C_ID C_NAME CITY PID
P01 Moisturiser XYZ 40 C01 Anaya DELHI P02
P02 Sanitizer LAC 35 C05 Prateek MUMBAI P05
P03 Bath Soap COP 25 C12 Geetanjali DELHI P01
P04 Shampoo TAP 95 C15 Abhishek CHENNAI P03
P05 Lens Solution COP 350
a. To display the details of Product whose Price is in the range of 40 and 120 (Both values included).
b. To display the ClientName, City from table Client and ProductName and Price from table Product, with
their corresponding matching P_ID.
c. To increase the Price of all the Products by 20.

3. Write SQL queries for the following:


Table: Employee Table: Job
EID NAME SALES JOBID JOBID JOBTITLE SALARY
E1 SUMIT 1100000 102 101 President 200000
E2 VIJAY 1300000 101 102 Vice President 125000
E3 AJAY 1400000 103 103 Admin Assistant 80000
E4 MOHIT 1250000 102 104 Account Manager 70000
E5 ADITYA 1450000 103 105 Accountant 65000
106 Sales Manager 80000
a. To display employee ids, names of employees, job ids with corresponding job titles.
b. To display names of employees, sales and corresponding job titles who have achieved sales more
than 1300000.
c. To display names and corresponding job titles of those employees who have 'SINGH' (anywhere) in
their names.
d. Identify foreign key in the table EMPLOYEE.
e. Write SQL command to change the JOBID to 104 of the EMPLOYEE with ID as E4 in the table
‘EMPLOYEE'.

You might also like