Chapter 9 Structured Query Language (SQL) Questions and Answers
Chapter 9 Structured Query Language (SQL) Questions and Answers
O
H
A
M
M
ED
M
AT
H
EE
N
L
R
Q & A || CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) April 25, 2025
Contents
LICENSE 3
R
3 MARKS QUESTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5 MARKS QUESTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
L
CHAPTER END EXERCISES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
N
EE
H
AT
M
ED
M
M
A
H
O
M
LICENSE
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Interna-
tional License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or
send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
“Karnataka Second PUC Computer Science Study Material / Student Notes” by L R Mohammed Matheen
is licensed under CC BY-NC-ND 4.0.
R
L
N
Figure 1: Licence
EE
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Interna-
tional License.
H
Portions of this work may include material under separate copyright. These materials are not covered by
AT
this Creative Commons license and are used by permission or under applicable copyright exceptions.
tional License.
ED
M
M
A
H
O
M
R
d) System Query Language
L
Answer: c
N
a) MySQL
EE
b) Oracle
c) MongoDB
d) PostgreSQL
Answer: c H
AT
3. SQL is case sensitive in which environment?
a) Windows
M
b) Linux
c) Mac
ED
d) Android
Answer: b
M
4. Which of the following is a correct SQL statement to create a database named Library?
a) MAKE DATABASE Library;
M
d) DATABASE Library;
H
Answer: c
O
b) Delete a database
c) Select a database for use
d) Exit SQL
Answer: c
R
c) TIME
d) All of the above
L
Answer: d
N
8. CHAR(n) datatype in MySQL stores data of:
a) Fixed length
EE
b) Variable length
c) Integer
d) Binary type
H
AT
Answer: a
a) PRIMARY KEY
b) FOREIGN KEY
c) UNIQUE
ED
d) DEFAULT
Answer: c
M
Answer: b
O
a) Deletes a table
b) Changes the structure of a table
c) Adds data to a table
d) Queries data
Answer: b
b) DELETE
c) DROP
d) ALTER
Answer: c
R
c) VIEW tablename
d) PRINT tablename
L
Answer: b
N
14. What type of key is formed by combining multiple attributes?
a) Foreign key
EE
b) Alternate key
c) Composite key
d) Candidate key
H
AT
Answer: c
15. What happens if you run an UPDATE statement without a WHERE clause?
M
a) Nothing happens
b) Syntax error
c) All records are updated
ED
b) INSERT INTO
A
c) PUT INTO
d) ENTER INTO
H
Answer: b
O
a) DD-MM-YYYY
b) MM-DD-YYYY
c) YYYY-MM-DD
d) Any format
Answer: c
b) LIKE
c) BETWEEN
d) ALL
Answer: a
R
c) MOD
d) ROUND
L
Answer: c
N
20. Which function is used to calculate exponential power in SQL?
a) EXP()
EE
b) ROUND()
c) POW()
d) SQRT()
H
AT
Answer: c
a) GROUP BY
b) ORDER BY
c) SORT BY
ED
d) ARRANGE BY
Answer: b
M
b) DOWN
A
c) DESC
d) LOWER
H
Answer: c
O
23. Which function returns the name of the day from a date?
M
a) DAYNAME()
b) DAY()
c) DATENAME()
d) DAYOFWEEK()
Answer: a
24. Which clause helps in fetching only unique values from a column?
a) ONLY
b) UNIQUE
c) DISTINCT
d) NON-REPEATED
Answer: c
R
c) Error
d) Infinity
L
Answer: b
N
26. Which function returns current date and time in SQL?
a) CURRENT()
EE
b) NOW()
c) TIME()
d) SYSDATE()
H
AT
Answer: b
a) LIKE
b) IN
c) AND
ED
d) IS
Answer: a
M
28. Which symbol is used to match any number of characters in SQL pattern matching?
a) _
M
b) %
A
c) *
d) #
H
Answer: b
O
a) RTRIM()
b) LTRIM()
c) TRIM()
d) REMOVE()
Answer: b
b) UCASE()
c) TOUPPER()
d) CAP()
Answer: b
31. Which clause is used to group rows that have the same values?
a) ORDER BY
b) GROUP BY
R
c) SET BY
d) UNION
L
Answer: b
N
32. Which function returns the number of characters in a string?
a) LEN()
EE
b) LENGTH()
c) SIZE()
d) COUNT()
H
AT
Answer: b
a) WHERE
b) HAVING
c) FILTER
ED
d) SELECT
Answer: a
M
b) HAVING
A
c) GROUP BY
d) FILTER
H
Answer: b
O
a) MAX()
b) TOP()
c) LAST()
d) HIGH()
Answer: a
36. Which clause in SQL is used to group records that have the same values in specified columns?
a) ORDER BY
b) GROUP BY
c) WHERE
d) HAVING
Answer: b
R
c) IS NULL
d) EQUAL NULL
L
Answer: c
N
38. What will be the result of 5 + NULL in SQL?
a) 5
EE
b) 0
c) NULL
d) Error
H
AT
Answer: c
a) MID()
b) SUBSTRING()
c) SLICE()
ED
d) CUT()
Answer: a
M
b) 123.5
A
c) 123.45
d) 123
H
Answer: b
O
a) ERASE
b) DELETE
c) REMOVE
d) DROP
Answer: d
b) 3
c) 1
d) 0
Answer: a
R
c) Restricts NULL values
d) Sets a foreign key
L
Answer: b
N
44. Which operator is used to match a value within a range?
a) IN
EE
b) RANGE
c) BETWEEN
d) BOUND
H
AT
Answer: c
a) ROUND()
b) MOD()
c) AVG()
ED
d) LCASE()
Answer: c
M
b) MONTH()
A
c) GETMONTH()
d) MTH()
H
Answer: b
O
47. Which of the following is a valid constraint that can be applied to enforce referential integrity
M
48. Which of the following conditions must be satisfied for a FOREIGN KEY to be added to a
table?
a) The table must have a DATE column
b) The referenced attribute must be of FLOAT type
c) The referenced column must be a PRIMARY KEY
d) The referenced table must be empty
Answer: c
49. Which SQL operator is used to check whether a column value falls between two values (inclu-
R
sive)?
a) IN
L
b) LIKE
c) RANGE
N
d) BETWEEN
EE
Answer: d
Answer: c
51. Assertion (A): SQL is used only for retrieving data from databases. Reason (R): SQL stands
ED
52. Assertion (A): VARCHAR stores variable-length character strings. Reason (R): CHAR and
H
53. Assertion (A): PRIMARY KEY allows duplicate values in a column. Reason (R): PRIMARY
KEY is used to uniquely identify each record.
a) Both A and R are true, and R is the correct explanation of A
54. Assertion (A): ALTER TABLE statement can be used to add a new column. Reason (R): ALTER
TABLE can modify the structure of an existing table.
a) Both A and R are true, and R is the correct explanation of A
R
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
L
d) A is true, but R is false
Answer: a
N
55. Assertion (A): The keyword DESC is used to sort records in descending order. Reason (R): The
EE
ORDER BY clause displays records in random order by default.
a) Both A and R are true, and R is the correct explanation of A
H
b) Both A and R are true, but R is not the correct explanation of A
AT
c) A is true, but R is false
d) A is false, but R is true
Answer: c
M
56. Assertion (A): SQL is a case-insensitive language. Reason (R): In SQL, ‘salary’ and ‘SALARY’
are treated as the same column names.
ED
Answer: a
A
57. Assertion (A): The CREATE TABLE command is used to define the structure of a new table.
Reason (R): CREATE TABLE can define attribute names, data types, and constraints.
H
58. Assertion (A): DEFAULT constraint ensures that every column must have a unique value.
Reason (R): DEFAULT sets a predefined value for a column when no value is provided.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
59. Assertion (A): DELETE statement removes a table from the database. Reason (R): DROP
TABLE statement is used to remove a table permanently.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
R
c) A is false, but R is true
d) A is true, but R is false
L
Answer: c
N
60. Assertion (A): The WHERE clause in SQL is used to filter groups formed by GROUP BY.
Reason (R): HAVING clause filters records before they are grouped.
EE
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
H
AT
d) Both A and R are false
Answer: d
M
61. Assertion (A): INSERT INTO command adds new records into a table. Reason (R): Records
can be inserted without specifying column names if all values are provided in correct order.
a) Both A and R are true, and R is the correct explanation of A
ED
62. Assertion (A): A FOREIGN KEY can reference a column that is not a primary key. Reason
A
(R): A foreign key ensures that each value exists in another table’s primary key column.
a) Both A and R are true, and R is the correct explanation of A
H
Answer: c
63. Assertion (A): ROUND() is used to round numbers to specified decimal places. Reason (R):
ROUND(283.2, 0) will return 283.2.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
64. Assertion (A): The % symbol in SQL is used to match zero or more characters. Reason (R):
The LIKE clause in SQL supports pattern matching using wildcards.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
R
d) A is false, but R is true
Answer: a
L
65. Assertion (A): The BETWEEN operator is inclusive of boundary values. Reason (R): BE-
N
TWEEN is used to test if a value lies between a specified range.
a) Both A and R are true, and R is the correct explanation of A
EE
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
H
AT
Answer: a
66. Assertion (A): You can use the alias keyword AS to rename a column in the output. Reason
M
Answer: c
67. Assertion (A): NOW() function returns the current system date and time. Reason (R): NOW()
M
68. Assertion (A): MID() function is used to extract a part of a string. Reason (R): MID() is a
numeric function used to perform arithmetic operations.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: c
69. Assertion (A): The TRIM() function is used to remove trailing spaces only. Reason (R): TRIM()
removes both leading and trailing spaces from a string.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
R
Answer: d
70. Assertion (A): The IS NULL operator is used to check for zero values. Reason (R): IS NULL
L
checks whether a column has NULL as its value.
N
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
EE
c) A is false, but R is true
d) A is true, but R is false
Answer: c
H
AT
FILL IN THE BLANKS
M
Answer: Primary
Answer: YYYY-MM-DD
M
9. To display all columns from a table, we use the symbol __________ in a SELECT statement.
Answer: *
10. The command to remove an entire table from the database is __________.
Answer: DROP TABLE
12. The __________ constraint ensures a column cannot have NULL values.
R
Answer: NOT NULL
L
13. The __________ function returns the current date and time.
Answer: NOW()
N
14. To define a column with fixed length string data, we use the datatype __________.
EE
Answer: CHAR
15. The __________ datatype stores numeric values with decimal points.
Answer: FLOAT
H
AT
16. The __________ function is used to round off numbers in SQL.
Answer: ROUND()
M
17. __________ is a special value in SQL used to represent missing or unknown information.
Answer: NULL
ED
18. The __________ constraint automatically fills in a column with a predefined value when no
input is given.
M
Answer: DEFAULT
19. To rename a column in the output of a SELECT query, we use the keyword __________.
M
Answer: AS
A
20. The __________ operator is used to check if a column value is within a set of values.
H
Answer: IN
O
22. The __________ function removes both leading and trailing spaces from a string.
Answer: TRIM()
24. The __________ command is used to view the structure of an existing table.
Answer: DESCRIBE
25. The __________ clause is used with SELECT to retrieve only unique values.
Answer: DISTINCT
26. The __________ constraint ensures all values in a column are different.
Answer: UNIQUE
27. The __________ operator is used to retrieve records where a column value lies within a specific
range.
Answer: BETWEEN
R
28. The __________ function extracts a part of a string.
L
Answer: MID()
29. A column that refers to a primary key in another table is called a __________ key.
N
Answer: foreign
EE
30. The __________ command permanently removes all records from a table and the table structure
itself.
Answer: DROP
H
AT
2 MARKS QUESTIONS
M
1. What is SQL?
Answer: SQL stands for Structured Query Language. It is a language used to create, manipulate, and
ED
retrieve data from relational databases like MySQL, Oracle, SQL Server, etc.
Answer: SQL is considered easy because its statements are made up of descriptive English words and it
is case-insensitive.
M
Answer: CHAR is a fixed-length datatype that pads unused characters with spaces, while VARCHAR is
H
R
...);
Example:
L
CREATE TABLE STUDENT(
N
RollNumber INT PRIMARY KEY,
SName VARCHAR(20) NOT NULL,
EE
SDateofBirth DATE,
GUID CHAR(12)
);
H
AT
8. What is the use of the DESCRIBE command in SQL?
Answer: The DESCRIBE or DESC command is used to view the structure of a table including column
names, data types, and constraints.
M
record.
Example:
M
Answer:
A
11. How do you add a new column to an existing table? Give syntax and example.
Answer:
M
13. Write the syntax to insert data into a table and give an example.
Answer:
Syntax: INSERT INTO tablename VALUES (value1, value2, ...);
Example:
INSERT INTO STUDENT VALUES (1, 'Atharv Ahuja', '2003-05-15', 444444444444);
14. What is the use of the SELECT statement? Give a simple example.
Answer: SELECT is used to retrieve data from a table.
R
Example:
SELECT * FROM STUDENT;
L
15. What is the purpose of the DISTINCT clause in a SELECT query?
N
Answer: DISTINCT is used to return only unique (non-duplicate) values in the output of a SELECT
statement.
EE
16. Give the syntax of the ORDER BY clause and state its default order.
Answer:
H
Syntax: SELECT * FROM tablename ORDER BY column_name [ASC|DESC];
AT
Default order is ascending (ASC).
Answer: WHERE filters rows before grouping, while HAVING filters groups formed by GROUP BY.
18. Write a query to display employee names and their annual income (Salary * 12), using column
ED
aliases.
Answer:
M
Answer: The LIKE operator is used for pattern matching using wildcards.
Example:
H
Answer: Single-row functions operate on a single value and return a single value.
Examples: UCASE(), ROUND()
3 MARKS QUESTIONS
2. Differentiate between DDL and DML commands with one example each.
Answer:
DDL (Data Definition Language) defines the structure of a database. Example: CREATE TABLE.
DML (Data Manipulation Language) is used to manage data in tables. Example: INSERT INTO.
R
3. Write the syntax of the CREATE TABLE command and give an example to create a STUDENT
table with RollNumber, Name, and DateOfBirth.
L
Answer:
N
Syntax:
EE
CREATE TABLE tablename (column1 datatype, column2 datatype, ...);
Example:
);
Answer:
1. NOT NULL – Ensures that a column cannot have NULL values.
M
5. What is a foreign key? Give its syntax and explain with an example.
A
Answer:
A foreign key is a column that refers to the primary key of another table.
H
Syntax:
O
Example:
6. Write a query to insert a record into the GUARDIAN table. Also, write a query to add a new
column Occupation.
Answer:
Insert:
INSERT INTO GUARDIAN VALUES (444444444444, 'Prithvi Raj', 'M', 'Doctor', 1200000);
Add column:
7. Write a query to update the salary of employee code 103 to 80000 and delete employee with code
104.
Answer:
R
Update:
L
UPDATE EMPLOYEE SET Salary = 80000 WHERE Ecode = 103;
Delete:
N
DELETE FROM EMPLOYEE WHERE Ecode = 104;
EE
8. What is the difference between DELETE and DROP commands? Give one use case each.
Answer:
H
DELETE removes specific rows but retains the table structure.
AT
Example: DELETE FROM STUDENT WHERE RollNumber = 1;
DROP removes the table structure entirely.
M
9. Explain the use of SELECT statement with WHERE and ORDER BY clauses using an example.
ED
Answer:
SELECT retrieves records from a table.
WHERE filters rows based on a condition.
M
Example:
10. Write a query using DISTINCT to display unique city names from the CUSTOMER table.
Also, explain its use.
O
Answer:
M
Query:
Explanation: DISTINCT is used to remove duplicate values from the result set.
11. Differentiate between the WHERE and HAVING clauses with example queries.
Answer:
WHERE filters rows before grouping;
12. Write queries to demonstrate the use of LIKE operator with the patterns:
a) Names starting with ‘A’
b) Names ending with ‘n’
R
c) Names containing ‘sh’
Answer:
L
a) SELECT * FROM EMPLOYEE WHERE Ename LIKE 'A%';
N
b) SELECT * FROM EMPLOYEE WHERE Ename LIKE '%n';
c) SELECT * FROM EMPLOYEE WHERE Ename LIKE '%sh%';
EE
13. What are wildcard characters in SQL? Explain % and _ with suitable examples.
Answer:
Wildcards are used with LIKE for pattern matching.
H
AT
% – Matches zero or more characters.
Example: 'K%' matches ‘Kiran’, ‘Kunal’
M
Answer:
a) SELECT * FROM SALE WHERE SAmount > 200000;
M
15. List any three aggregate functions in SQL with their purpose.
H
Answer:
1. SUM() – Returns total sum of values.
O
16. Write a query using GROUP BY to count the number of employees in each department.
Answer:
17. Explain the use of MOD() and ROUND() functions with examples.
Answer:
18. What does the NOW() function return? Also, write a query to retrieve it.
Answer:
NOW() returns the current date and time.
Query:
SELECT NOW();
R
19. Write the difference between single-row functions and aggregate functions. Give two examples
L
of each.
Answer:
N
Single-row functions operate on each row. Example: UCASE(), ROUND()
EE
Aggregate functions operate on a group of rows. Example: SUM(), MAX()
5 MARKS QUESTIONS
M
QUESTION 1
Given Table: STUDENT
A
H
a. Write a CREATE TABLE command to create the STUDENT table with appropriate data types.
R
L
ANSWER 1
N
a.
EE
CREATE TABLE STUDENT (
RollNumber INT PRIMARY KEY,
SName VARCHAR(30),
H
AT
SDateofBirth DATE,
GUID CHAR(12)
);
M
b.
ED
c.
d.
H
UPDATE STUDENT
O
e.
QUESTION 2
Given Table: EMPLOYEE
R
E003 Chetan 28000 D01
L
Write SQL queries for the following:
N
a. Write the CREATE TABLE command for EMPLOYEE with relevant types.
EE
b. List employees working in department D01.
ANSWER 2
M
a.
A
Ename VARCHAR(30),
O
Salary INT,
DeptId CHAR(4)
M
);
b.
c.
d.
UPDATE EMPLOYEE
SET Salary = 32000
WHERE Ename = 'Chetan';
R
e.
L
ORDER BY Salary DESC;
N
EE
QUESTION 3
Given Table: GUARDIAN
H
AT
GUID GName GPhone Income
ANSWER 3
a.
b.
R
SELECT GName FROM GUARDIAN
WHERE GPhone IS NULL;
L
c.
N
SELECT COUNT(*) FROM GUARDIAN
EE
WHERE Income > 300000;
d.
UPDATE GUARDIAN
H
AT
SET GPhone = '9012345678'
WHERE GUID = '222222222222';
M
e.
QUESTION 4
Given Table: INVENTORY
A
H
R
L
ANSWER 4
N
a.
EE
CREATE TABLE INVENTORY (
CarId CHAR(5) PRIMARY KEY,
CarName VARCHAR(30),
H
AT
Price DECIMAL(10,2),
FuelType VARCHAR(10)
);
M
b.
ED
c.
GROUP BY FuelType;
A
d.
H
UPDATE INVENTORY
O
e.
QUESTION 5
Given Table: SALE
R
Write SQL queries for the following:
L
a. Write the CREATE TABLE statement for SALE.
N
EE
b. Show all sales above 550000.
H
AT
d. Update SalePrice for invoice I002 to 550000.
ANSWER 5
M
a.
M
CarId CHAR(5),
CustId CHAR(5),
H
SalePrice DECIMAL(10,2)
O
);
M
b.
c.
d.
UPDATE SALE
SET SalePrice = 550000.00
WHERE InvoiceNo = 'I002';
e.
R
L
N
QUESTION 6
EE
Given Table: CUSTOMER
H
AT
C001 Ananya Sen Lajpat Nagar 9811122233 [email protected]
C002 Ravi Verma Rohini Sector 3 9822233344 [email protected]
M
ANSWER 6
a.
b.
R
SELECT CustName FROM CUSTOMER
L
WHERE CustAdd LIKE '%Rohini%';
N
c.
EE
SELECT COUNT(*) FROM CUSTOMER
WHERE Email LIKE '%gmail.com';
d.
H
AT
UPDATE CUSTOMER
SET Phone = '9876543210'
WHERE CustName = 'Ravi Verma';
M
e.
ED
QUESTION 7
A
R
L
ANSWER 7
N
a.
EE
CREATE TABLE PRODUCT (
ProdID CHAR(5) PRIMARY KEY,
ProdName VARCHAR(30),
H
AT
Price INT,
Stock INT
);
M
b.
ED
c.
d.
H
UPDATE PRODUCT
O
SET Stock = 12
WHERE ProdName = 'Monitor';
M
e.
QUESTION 8
Given Table: BOOK
R
Write SQL queries for the following:
L
a. Write the CREATE TABLE statement for BOOK.
N
EE
b. Show titles priced above 500.
H
AT
d. Update price of ‘Python Programming’ to 500.
ANSWER 8
M
a.
M
Title VARCHAR(50),
Author VARCHAR(50),
H
Price INT
O
);
M
b.
c.
d.
UPDATE BOOK
SET Price = 500
WHERE Title = 'Python Programming';
e.
R
L
N
QUESTION 9
EE
Given Table: SUPPLIER
H
AT
S001 Ram Traders Delhi
S002 Om Supplies Gurgaon
M
ANSWER 9
a.
b.
R
WHERE City = 'Delhi';
L
c.
N
WHERE City = 'Gurgaon';
EE
d.
UPDATE SUPPLIER
SET City = 'Noida'
H
AT
WHERE Name = 'Om Supplies';
e.
M
QUESTION 10
M
1 2024-08-01 P
O
2 2024-08-01 A
M
R
ANSWER 10
L
a.
N
CREATE TABLE ATTENDANCE (
EE
RollNo INT,
Date DATE,
Status CHAR(1)
);
H
AT
b.
c.
ED
d.
M
UPDATE ATTENDANCE
SET Status = 'P'
A
e.
O
ORDER BY RollNo;
QUESTION 11
Given Table: MARKS
1 Math 85
2 Math 78
1 Science 90
R
Write SQL queries for the following:
L
a. Create the MARKS table.
N
b. Find the average marks in Math.
EE
c. Show maximum marks scored in Science.
ANSWER 11
a.
M
RollNo INT,
Subject VARCHAR(30),
A
Marks INT
);
H
O
b.
M
c.
d.
UPDATE MARKS
SET Marks = 82
WHERE RollNo = 2 AND Subject = 'Math';
e.
R
L
QUESTION 12
N
Given Table: PRODUCT
EE
ProdID Name Price Quantity
P01 Pen
H
10 100
AT
P02 Notebook 50 80
M
ANSWER 12
a.
Price INT,
Quantity INT
);
b.
c.
R
SELECT MAX(Price) AS MaxPrice FROM PRODUCT;
L
d.
N
UPDATE PRODUCT
SET Quantity = 120
EE
WHERE Name = 'Pen';
e.
QUESTION 13
Given Table: SALES
M
ANSWER 13
R
a.
L
CREATE TABLE SALES (
SaleID CHAR(5) PRIMARY KEY,
N
Item VARCHAR(30),
Amount INT
EE
);
b.
c.
d.
M
UPDATE SALES
SET Amount = 180
M
e.
H
QUESTION 14
Given Table: ATTENDANCE
2024-08-01 1 P
2024-08-01 2 A
2024-08-02 1 P
R
Write SQL queries for the following:
L
a. Write the CREATE TABLE statement for ATTENDANCE.
N
b. Count how many days RollNo 1 was present.
EE
c. Count total records for each attendance status.
ANSWER 14
a.
M
Date DATE,
RollNo INT,
A
Status CHAR(1)
);
H
O
b.
M
c.
d.
UPDATE ATTENDANCE
SET Status = 'P'
WHERE RollNo = 2 AND Date = '2024-08-01';
e.
R
L
QUESTION 15
N
Given Table: EMPLOYEE
EE
EmpID Name Salary
E01 Aarav
H 45000
AT
E02 Tanya 50000
E03 Rohan 42000
M
ANSWER 15
a.
b.
R
c.
L
SELECT MIN(Salary) AS MinSalary FROM EMPLOYEE;
N
d.
EE
UPDATE EMPLOYEE
SET Salary = 46000
WHERE Name = 'Rohan';
H
AT
e.
QUESTION 16
M
R
ANSWER 16
L
a.
N
CREATE TABLE GUARDIAN (
EE
GUID CHAR(5) PRIMARY KEY,
GName VARCHAR(50),
Income INT
);
H
AT
b.
c.
ED
d.
UPDATE GUARDIAN
M
e.
O
QUESTION 17
Given Table: LIBRARY
R
Write SQL queries for the following:
L
a. Write the CREATE TABLE command for LIBRARY.
N
b. Find the total cost of all books.
EE
c. Display the most expensive book.
ANSWER 17
a.
M
Price INT
);
H
O
b.
M
c.
d.
UPDATE LIBRARY
SET Price = 470
WHERE Title = 'DBMS Concepts';
e.
R
L
QUESTION 18
N
Given Table: PURCHASE
EE
PurchaseID Item Quantity Rate
P001 Pencil
H 100 5
AT
P002 Eraser 50 3
P003 Sharpener 60 6
M
ANSWER 18
a.
b.
R
SELECT SUM(Quantity) AS TotalQuantity FROM PURCHASE;
L
c.
N
d.
EE
UPDATE PURCHASE
SET Quantity = 70
WHERE Item = 'Eraser';
H
AT
e.
ORDER BY Item;
ED
QUESTION 19
M
R
ANSWER 19
L
a.
N
CREATE TABLE ORDERS (
EE
OrderID CHAR(5) PRIMARY KEY,
Customer VARCHAR(30),
Amount INT
);
H
AT
b.
c.
ED
d.
UPDATE ORDERS
M
e.
O
QUESTION 20
Given Table: CLASSMARKS
101 English 88
102 English 92
103 English 80
R
Write SQL queries for the following:
L
N
b. Find average marks in English.
EE
c. Find minimum marks in the subject.
ANSWER 20
a.
M
Subject VARCHAR(30),
Marks INT
A
);
H
b.
O
c.
d.
UPDATE CLASSMARKS
SET Marks = 85
WHERE RollNo = 103;
e.
R
Exercise 1: Answer the following questions
L
a) RDBMS stands for Relational Database Management System.
N
Two RDBMS software: MySQL, Oracle
EE
b)
- ORDER BY: Sorts query results based on one or more columns.
- GROUP BY: Groups rows with identical values for aggregate functions.
c) H
AT
Single Row Functions Aggregate Functions
M
Return one result per row Return one result for entire group
M
d) Cartesian Product: The result of combining every row from one table with every row from another
table.
M
e)
A
f)
i) DAYNAME()
ii) MID() or SUBSTRING()
iii) MONTHNAME()
iv) UPPER() or UCASE()
a)
SELECT POW(2,3);
→8
b)
SELECT ROUND(342.9234,-1);
R
→ 340
L
c)
N
SELECT LENGTH("Informatics Practices");
EE
→ 23
d)
H
SELECT YEAR("1979/11/26"), MONTH("1979/11/26"), DAY("1979/11/26"),
AT
↪ MONTHNAME("1979/11/26");
e)
ED
Given table MOVIE with columns: MovieID, MovieName, Category, ReleaseDate, ProductionCost, Busi-
O
nessCost
M
a)
b)
c)
d)
e)
SELECT MovieID, MovieName, ProductionCost FROM MOVIE WHERE ProductionCost > 10000 AND
↪ ProductionCost < 100000;
R
f)
L
SELECT * FROM MOVIE WHERE Category IN ('Comedy', 'Action');
N
g)
EE
SELECT * FROM MOVIE WHERE ReleaseDate IS NULL;
H
AT
Exercise 4: Creating and Modifying Tables in SPORTS Database
M
a)
b)
d)
O
DESC TEAM;
M
e)
f)
g)
R
SecondTeamID INT,
FirstTeamScore INT,
L
SecondTeamScore INT
);
N
EE
Exercise 5: Queries on MATCH_DETAILS Table
H
AT
a)
SELECT MatchID FROM MATCH_DETAILS WHERE FirstTeamScore > 70 AND SecondTeamScore > 70;
M
b)
SELECT MatchID FROM MATCH_DETAILS WHERE FirstTeamScore < 70 AND SecondTeamScore > 70;
ED
c)
M
d)
A
e)
O
a) Insert handkerchief:
ALTER TABLE COST ADD CONSTRAINT FK_UCode FOREIGN KEY (UCode) REFERENCES
↪ UNIFORM(UCode);
R
ALTER TABLE UNIFORM ADD CONSTRAINT chk_UName CHECK (UName IS NOT NULL);
L
d) Price must be > 0:
ALTER TABLE COST ADD CONSTRAINT chk_price_gt_zero CHECK (Price > 0);
N
EE
Exercise 7: Product Table Operations
H
AT
a)
Manufacturer VARCHAR(30)
);
M
c)
SELECT PCode, PName, UPrice FROM Product ORDER BY PName DESC, UPrice ASC;
A
H
d)
O
e)
OR
f)
R
g)
L
SELECT Manufacturer, COUNT(*) FROM Product GROUP BY Manufacturer;
N
h)
EE
SELECT PName, AVG(UPrice) FROM Product GROUP BY PName;
i)
k)
ED
a)
H
b)
M
or
c)
SELECT CarName FROM INVENTORY WHERE FuelType = 'Petrol' ORDER BY Price DESC LIMIT 1;
d)
R
SELECT AVG(Discount), SUM(Discount) FROM INVENTORY WHERE CarName = 'Baleno';
L
e)
N
SELECT COUNT(*) FROM INVENTORY WHERE Discount = 0;
EE
For more information Visit:
https://matheenhere.blogspot.com
H
AT
M
ED
M
M
A
H
O
M