Font size
WorksheetsSQL Functions Quiz
Total questions: 100
Worksheet time: 50mins
The avg() function in MySQL is an example of ______________.
Math Function
Text Function
Date Function
Aggregate Function
The __________ Command can be used to make changes in the rows of a table in SQL.
SELECT
UPDATE
DELETE
INSERT
The SQL Command that will display the current time and date is:
Select now();
Select date();
Select time();
Select sysdate();
The mid() function in MySQL is an example of ______________.
Math Function
Text Function
Date Function
Aggregate Function
The __________ function is used in SQL to find one string in another.
Instr()
Locate()
Find()
Search()
MID() and SUBSTR() function in SQL serve the same purpose. (Yes/No)
Yes
No
What is the output of the SQL command: Select round(15.193, -1)?
10
15.2
15
20
Which SQL query will display the date after 10 days from the current date on your system?
Select date_add(curdate(), interval 10 day);
Select curdate()+10;
Select sysdate()+10;
Select adddate(curdate(), 10);
What is the output of the SQL command: Select SUBSTR('ABCDEFG', -5, 3)?
DEF
CDE
UBS
EFG
Which keyword is used to arrange the result of the ORDER BY clause in descending order?
DSEC
DES
DESC
ORDER_DESC
The clause that is used to arrange the result of SQL command into groups
Order by
Group in
Groups by
Group by
Find the Output of SQL command: select concat (concat ('Inform', 'atics'), 'Practices');
Informatics Practices
Informatic Practices
Inform practices
Inform atics practices
Write the output of the following SQL command: select round (19.88,1);
19.88
19.8
19.9
20.0
The now() function in MySQL is an example of:
Math function
Text function
Date Function
Aggregate Function
The ............ command can be used to make changes in the structure of a table in SQL.
ALTER
UPDATE
MODIFY
CHANGE
SELECT
Write the SQL command that will display the time and date at which the command got executed.
Select sysdate();
Select now();
Select current_date();
Select current_time();
Write the output of the following SQL command: select round(15.872,1);
15.87
15.9
15.8
16
Manish wants to select all the records from a table named "Students" where the value of the column "FirstName" ends with an "a". Which of the following SQL statement will do this?
SELECT * FROM Students WHERE FirstName = 'a';
SELECT * FROM Students WHERE FirstName LIKE '%a';
SELECT * FROM Students WHERE FirstName LIKE 'a%';
SELECT * FROM Students WHERE FirstName LIKE '%a%';
The command can be used to add a new column to the table.
ALTER
CREATE
INSERT
UPDATE
Which SQL command is used to describe the structure of the table?
DESC
SELECT
SHOW
ALTER
Foreign Key in a table is used to enforce:
Data dependency
Referential Integrity
Views
Index Locations
A table ‘Student’ contains 5 rows and 4 columns initially. 2 more rows are added and 1 more column is added. What will be the degree and cardinality of the table student after adding these rows and columns?
7, 5
5, 7
5, 5
None of the above
Insert into student values(1,’ABC’,’10 Hari Nagar’) is a type of which command:
DML
DDL
TCL
DCL
What will be the output of - select mid(‘Python Programming’,3,9);
ton Progr
ton Progr
hton Prog
htonProg
Write the output of the following SQL statement: SELECT TRUNCATE(15.79,-1), TRUNCATE(15.79,0), TRUNCATE(15.79,1);
15 15 15.7
10 15.7 15.9
10 15 15.7
10 10 15.9
The COUNT() in MySQL is an example of:
Math function
Text function
Date Function
Aggregate Function
....... which of the following sublanguages of SQL is used to query?
DDL
DML
TCL
DCL
Which command is used to retrieve information from the database and to insert tuples into, delete tuples from, and modify tuples in the database?
DML
DDL
Query
Relational Schema
The ______ clause of SELECT query allows us to select only those rows in the result that satisfied a specified condition.
WHERE
FROM
HAVING
LIKE
What will be the output of the following SQL command: `select substr("COMPUTER",3,4);`
MPUT
PUTE
PU
MP
The now() function in MySQL is an example of ______.
Math function
Text function
Date Function
Aggregate Function
Which command is used to make the changes in a table permanent?
ROLLBACK
COMMIT
SAVEPOINT
DELETE
Which SQL command will display the current month from the date and time?
MONTH()
CURRENT_DATE()
NOW()
DATE()
Which of the following keywords will you use in the following query to display all the records of students whose name starts with S? `SELECT * from student where name__"S%"`
LIKE
IN
BETWEEN
DISTINCT
Which of the following is an aggregate function?
Upper()
Trim()
Date()
Sum()
Write the output of the following SQL command: SELECT left("Jammu Region", 5);
Region
Jammu
Jammu Region
None of the above.
What will be the output of the following code? SELECT MOD(14,3);
1
2
3
0
What will be the result of the following query based on the table given here? SELECT COUNT(Salary) FROM Instructor;
4
5
6
7
Write the command to delete all the data of the table 'activity' retaining only structure.
DELETE FROM activity;
DROP TABLE activity;
TRUNCATE TABLE activity;
DELETE * FROM activity;
Write the output for the following SQL command: SELECT round(15.193, -1);
15
10
20
0
Write a SQL query to display date after 20 days of current date on your system.
SELECT CURDATE() + 20;
SELECT DATE_ADD(CURDATE(), INTERVAL 20 DAY);
SELECT CURDATE() + INTERVAL 20 DAY;
SELECT ADDDATE(CURDATE(), 20);
Write the output for the following SQL command: SELECT SUBSTR('ABCDEFG', -5, 3);
CDE
DEF
ABC
GFE
Which keyword is used to arrange the result of order by clause in descending order?
DSEC
DESC
ORDER_DESC
REVERSE
Write the output of the following SQL command: `Select round(14.872,1)`
14.87
14.9
14.8
15
The ________ command can be used to change the size of a column in a table.
UPDATE
ALTER
MODIFY
DELETE
The ________ command can be used to make changes in the rows of a table in SQL.
INSERT
ALTER
UPDATE
DELETE
Write the output of the following SQL command: `select round(49.88);`
49.88
49.8
49.0
50
Write the output of the following SQL command: `select round(19.88,1);`
19.88
19.8
19.9
20.0
Select count(*) from Employee; The above query will not consider the following:
Numeric value
Text value
Null value
Date value
Which of the following is/are not correct aggregate functions in SQL?
AVG()
COUNT()
TOTAL()
MAX()
The ________ command can be used to make changes in the definition of a table in SQL.
UPDATE
ALTER
MODIFY
DELETE
Write the SQL clause used to sort the records of a table.
GROUP BY
ORDER BY
SORT BY
FILTER BY
Write the output of the following SQL command: `select round(15.857,-1);`
15.8
15.9
15.0
20
The now() function in MySQL is an example of _____________.
Math function
Text function
Date Function
Aggregate Function
The command that can be used to make changes in the structure of a table in SQL is _____________.
ALTER
UPDATE
MODIFY
CHANGE
Which SQL command will display the time and date at which the command got executed?
SELECT TIME();
SELECT DATE();
SELECT NOW();
SELECT CURRENT();
In SQL, NULL value means:
0 value
1 value
None value
None of the above
Find the output of the SQL query: SELECT MOD(11, 3);
1
2
3
0
The MAX() function in MySQL is an example of _____________.
Math function
Text function
Date Function
Aggregate Function
Write the output of the following SQL command: select round(314.82,-1);
314.0
310.0
314.8
300.0
What will be the output of the following SQL command: SELECT LTRIM(" RAJKUMAR ");
"RAJKUMAR"
" RAJKUMAR"
"RAJKUMAR "
"RAJKUMAR " (with spaces removed from right side)
Write the output of the following SQL command: select pow(2.37,3.45);
17.62
19.62
18.35
15.82
Having clause is used with _____________ function.
Math function
Text function
Aggregate function
Date function
What is the output of the query: `select instr('Toolbarbar','bar');`?
3
5
7
9
The `alter()` function in MySQL is part of which command?
DDL command
DML command
TCL command
DCL command
Which command can be used to arrange data in some order in a table in SQL?
GROUP BY
ORDER BY
SELECT
WHERE
Which clause is used with the SELECT command to search for a specific pattern in strings?
WHERE
LIKE
GROUP BY
HAVING
What is the difference between single row functions and multiple row functions?
Single row functions work on multiple rows, while multiple row functions work on one row.
Single row functions return one output per row, while multiple row functions return one output for a group of rows.
Single row functions are used for sorting, while multiple row functions are used for filtering.
Single row functions are used for grouping, while multiple row functions are used for ordering.
What is the difference between the ORDER BY and GROUP BY clause when used along with the SELECT statement?
ORDER BY is used for grouping rows, while GROUP BY is used for sorting rows.
ORDER BY is used to sort rows, while GROUP BY is used to group rows based on column values.
ORDER BY is used for filtering rows, while GROUP BY is used for aggregating rows.
ORDER BY is used for pattern matching, while GROUP BY is used for searching.
Consider the decimal number X with value 8459.2654. Write the SQL command to round it off to a whole number.
`select round(8459.2654, 0);`
`select round(8459.2654, 1);`
`select round(8459.2654, -1);`
`select round(8459.2654, 2);`
Consider the decimal number X with value 8459.2654. Write the SQL command to round it off to 2 places before the decimal.
`select round(8459.2654, 0);`
`select round(8459.2654, 1);`
`select round(8459.2654, -2);`
`select round(8459.2654, 2);`
Anjali writes the following commands with respect to a table `employee` having fields: `empno`, `name`, `department`, and `commission`: - Command1: `Select count(*) from employee;` - Command2: `Select count(commission) from employee;` She gets the output as 4 for the first command but gets an output of 3 for the second command. Why is there a difference in the outputs?
Command1 counts all rows in the table, including NULL values, while Command2 only counts non-NULL values in the `commission` column.
Command1 counts only non-NULL values in the table, while Command2 counts all rows in the `commission` column.
Both commands count all rows in the table, but Command2 excludes duplicate values.
Command1 and Command2 both count only non-NULL values in the table.
Consider the SQL string: "Preoccupied". Write the SQL command to display the substring "cup".
select substr("Preoccupied", 4);
select substr("Preoccupied", 6, 3);
select substr("Preoccupied", 1, 3);
select substr("Preoccupied", 8, 3);
Consider the SQL string: "Preoccupied". Write the SQL command to display the first 4 letters of the string.
select left("Preoccupied", 4);
select substr("Preoccupied", 1, 4);
select right("Preoccupied", 4);
select mid("Preoccupied", 4);
What is the difference between the `WHERE` and `HAVING` clauses when used along with the `SELECT` statement?
`WHERE` is used to filter rows before grouping, while `HAVING` is used to filter groups after grouping.
`WHERE` is used to filter groups, while `HAVING` is used to filter rows.
Both `WHERE` and `HAVING` are used to filter rows, but `HAVING` supports aggregate functions.
`WHERE` is used to filter rows, while `HAVING` is used to filter rows without aggregate functions.
What is the difference between the `UPDATE` and `ALTER` commands in SQL?
`UPDATE` is used to modify the structure of a table, while `ALTER` is used to modify data in a table.
`UPDATE` is used to modify data in a table, while `ALTER` is used to modify the structure of a table.
Both `UPDATE` and `ALTER` are used to modify data in a table.
`UPDATE` is used to delete data, while `ALTER` is used to add new rows.
What is the output of the query `SELECT SUBSTR('Aakila', -3);`?
'Aak'
'ila'
'kil'
'Aakila'
What is the output of the query `SELECT LEFT('Toolbar', 4);`?
'Tool'
'Toolb'
'Toolbar'
'bar'
Why does the query `SELECT count(*) FROM FLIGHT;` return 5, while `SELECT count(DESTINATION) FROM FLIGHT;` returns 3?
The column DESTINATION contains NULL values, and aggregate functions like COUNT ignore NULL values.
The column DESTINATION contains duplicate values, and COUNT ignores duplicates.
The column DESTINATION is empty, so COUNT returns 0.
The column DESTINATION contains only numeric values, and COUNT ignores non-numeric values.
What is the output of the query `SELECT MOD(11,4) "Modulus", POWER(3,2) "Raised";`?
Modulus: 2, Raised: 6
Modulus: 3, Raised: 9
Modulus: 1, Raised: 6
Modulus: 3, Raised: 6
What is the output of the query `SELECT LENGTH('CORONA COVID-19');`?
15
14
16
13
What is the output of the query `SELECT LCASE('COMputer Science');`?
'COMputer Science'
'computer science'
'COMPUTER SCIENCE'
'Computer Science'
What SQL command would you use to round the number 7459.3654 to a whole number?
select round(7459.3654, 0)
select round(7459.3654, -1)
select round(7459.3654, 1)
select round(7459.3654, 2)
What SQL command would you use to round the number 7459.3654 to two places before the decimal?
select round(7459.3654, 2)
select round(7459.3654, -2)
select round(7459.3654, 0)
select round(7459.3654, -1)
Why does the SQL command `SELECT COUNT(COMMISSION) FROM EMPLOYEE` return a lower count compared to `SELECT COUNT(*) FROM EMPLOYEE`?
Because the column commission contains NULL values, which are excluded in aggregate functions.
Because the column commission contains duplicate values.
Because the column commission contains only numeric values.
Because the column commission contains empty strings.
Which SQL command can be used to extract the substring "MOT" from the string "SELFMOTIVATION" starting at position 5?
select substr("SELFMOTIVATION", 5, 3)
select substr("SELFMOTIVATION", 5, 5)
select substr("SELFMOTIVATION", 3, 5)
select substr("SELFMOTIVATION", 5, 2)
Which SQL command can be used to find the position of the substring "MOTIV" in the string "SELFMOTIVATION"?
select instr("SELFMOTIVATION", "MOTIV")
select substr("SELFMOTIVATION", "MOTIV")
select position("SELFMOTIVATION", "MOTIV")
select locate("SELFMOTIVATION", "MOTIV")
What is the main objective of datatypes in SQL?
To identify the type of data and its associated functions.
To store only numeric data in a table.
To perform mathematical operations on data.
To create relationships between tables.
Which SQL command would you use to round the decimal number 278.6975 to give an output of 279?
select round(278.6975, 0)
select round(278.6975, -1)
select round(278.6975, 1)
select round(278.6975, 2)
Which SQL command would you use to round the decimal number 278.6975 to give an output of 280?
select round(278.6975, -1)
select round(278.6975, 0)
select round(278.6975, 1)
select round(278.6975, 2)
Consider a table "Employee" with fields - empno, name, department, salary. Manvendra has entered the following SQL command: `SELECT * FROM Employee where Salary = NULL;` But the query is not executing successfully. What do you suggest to him in order to execute this query correctly?
Use `SELECT * FROM Employee where Salary IS NULL;`
Use `SELECT * FROM Employee where Salary = 0;`
Use `SELECT * FROM Employee where Salary != NULL;`
Use `SELECT * FROM Employee where Salary IS NOT NULL;`
Write a SQL query to display the details of those employees whose Salary column has some values.
SELECT * FROM Employee where Salary IS NOT NULL;
SELECT * FROM Employee where Salary = NULL;
SELECT * FROM Employee where Salary > 0;
SELECT * FROM Employee where Salary IS NULL;
Consider the following SQL string: "Master Planner". Write SQL commands to display the position of the substring 'Plan' in the string "Master Planner".
SELECT instr("Master Planner", "Plan");
SELECT substr("Master Planner", 1, 6);
SELECT right("Master Planner", 4);
SELECT instr("Master Planner", "Master");
What are multiple row functions?
Functions that operate on multiple rows and return a single result.
Functions that operate on a single row and return multiple results.
Functions that operate on multiple rows and return multiple results.
Functions that operate on a single row and return a single result.
Consider the decimal number N with value 87654.9876. Write commands in SQL to round it off to a whole number.
SELECT round(87654.9876, 0);
SELECT round(87654.9876, -1);
SELECT round(87654.9876, 1);
SELECT round(87654.9876, 2);
State two differences between single row functions and multiple row functions.
Single row functions operate on each row individually, while multiple row functions operate on a group of rows.
Single row functions return multiple results, while multiple row functions return a single result.
Single row functions are used for aggregation, while multiple row functions are used for formatting.
Single row functions operate on a group of rows, while multiple row functions operate on each row individually.
What is the difference between single row functions and multiple row functions in SQL?
Single row functions return one output per group, whereas multiple row functions return one output per row.
Single row functions return one output per row, whereas multiple row functions return one output per group.
Single row functions and multiple row functions both return one output per row.
Single row functions and multiple row functions both return one output per group.
What is the purpose of the "order by" clause in SQL?
To group rows in a column and apply aggregate functions.
To sort the contents of a table in ascending or descending order based on a specified column.
To filter rows based on a condition.
To join two tables based on a common column.
What is the output of the following SQL query: `Select round(123.93);`?
123
124
123.9
123.93
What is the correct SQL command to extract the substring "Helps" from the string "Mental Toughness Helps You Succeed"?
`Select mid("Mental Toughness Helps You Succeed", 8, 9);`
`Select mid("Mental Toughness Helps You Succeed", 8, 5);`
`Select left("Mental Toughness Helps You Succeed", 6);`
`Select right("Mental Toughness Helps You Succeed", 7);`
