In this set of 30 multiple-choice questions (MCQs), we cover essential SQL Server functions and expressions, including Aggregate Functions (SUM, AVG, COUNT), String Functions (LEN, CONCAT), Date Functions (GETDATE, DATEADD), and Mathematical Functions. These questions are ideal for beginners and intermediate learners to test their SQL knowledge and understanding of SQL Server functions.
Aggregate Functions
Which of the following is used to calculate the total sum of values in a column in SQL Server?
A) COUNT
B) AVG
C) SUM
D) MIN
What does the COUNT function do in SQL Server?
A) Adds the values
B) Returns the number of rows
C) Finds the average value
D) Returns the highest value
What will the AVG function return when used on a column of numerical values?
A) The sum of all values
B) The median of values
C) The average of values
D) The minimum value
Which function can be used to get the maximum value in a column?
A) MAX
B) MIN
C) COUNT
D) SUM
Which of the following functions does not consider NULL values in SQL Server?
A) SUM
B) COUNT
C) AVG
D) MAX
What is the return type of the COUNT function when used on a numeric column?
A) Integer
B) Decimal
C) Float
D) String
Which aggregate function will return the smallest value in a column?
A) MAX
B) SUM
C) MIN
D) COUNT
What is the purpose of the GROUP BY clause in aggregate functions?
A) Filters records based on condition
B) Groups records into summary
C) Sorts records in ascending order
D) Joins two tables together
String Functions
Which function in SQL Server is used to concatenate two or more strings?
A) LEN
B) CONCAT
C) SUBSTRING
D) CHARINDEX
The LEN function returns the length of a string excluding which of the following?
A) Spaces at the beginning
B) Spaces at the end
C) Punctuation marks
D) All spaces
Which function returns the position of a substring within a string?
A) SUBSTRING
B) CHARINDEX
C) CONCAT
D) REPLACE
What does the LEFT function do in SQL Server?
A) Returns characters from the end of the string
B) Returns characters from the beginning of the string
C) Removes the first character of the string
D) Changes the case of the string
Which function is used to replace a substring within a string in SQL Server?
A) REPLACE
B) CHARINDEX
C) CONCAT
D) LEFT
The TRIM function is used to remove which characters from a string?
A) Extra spaces only
B) Special characters only
C) Leading and trailing spaces
D) Punctuation marks
What is the return value of the UPPER function in SQL Server?
A) Converts a string to lowercase
B) Converts a string to uppercase
C) Returns the length of a string
D) Reverses the string
The RIGHT function in SQL Server is used to:
A) Extract characters from the left side of the string
B) Extract characters from the right side of the string
C) Replace characters in the string
D) Convert string to uppercase
Date Functions
Which SQL Server function is used to get the current date and time?
A) GETDATE
B) CURRENT_DATE
C) NOW
D) DATEADD
What will the DATEADD function do in SQL Server?
A) Adds or subtracts a specified time interval to a date
B) Returns only the date part of a date-time value
C) Converts a string to a date
D) Extracts a part of a date (like year, month)
Which function can be used to extract the year from a date in SQL Server?
A) YEAR
B) MONTH
C) DAY
D) GETDATE
What does the DATEDIFF function do?
A) Finds the difference between two dates
B) Adds two dates together
C) Converts a date to a string
D) Returns the current date
Which function returns the current system date in SQL Server?
A) SYSDATETIME
B) GETDATE
C) NOW
D) CURRENT_TIMESTAMP
What does the DATEPART function do in SQL Server?
A) Extracts a part of the date (e.g., month, day)
B) Converts a date into a specific format
C) Returns the total number of days in a month
D) Calculates the number of seconds between two dates
How does the CURRENT_TIMESTAMP function behave in SQL Server?
A) Returns the date with no time component
B) Returns the current date and time of the system
C) Adds a specified interval to the date
D) Converts a string to a timestamp
The GETDATE function returns the date and time of the system in which format?
A) yyyy-mm-dd
B) mm-dd-yyyy
C) yyyy-mm-dd hh:mm:ss
D) dd-mm-yyyy
Which function can you use to add months to a given date in SQL Server?
A) DATEADD
B) MONTH
C) GETDATE
D) DATEDIFF
Mathematical Functions
Which function in SQL Server returns the absolute value of a number?
A) ABS
B) ROUND
C) CEILING
D) FLOOR
The CEILING function in SQL Server returns:
A) The highest integer greater than or equal to a number
B) The lowest integer greater than or equal to a number
C) The square root of a number
D) The integer part of a number
What does the FLOOR function do in SQL Server?
A) Returns the nearest whole number greater than or equal to the value
B) Returns the nearest whole number less than or equal to the value
C) Returns the absolute value of a number
D) Rounds a number to the nearest integer
Which SQL Server function can be used to round a number to a specified number of decimal places?
A) ROUND
B) ABS
C) CEILING
D) FLOOR
Which function is used to return the square root of a number in SQL Server?
A) POWER
B) SQRT
C) EXP
D) LOG
Answer Key
Qno
Answer
1
C) SUM
2
B) Returns the number of rows
3
C) The average of values
4
A) MAX
5
B) COUNT
6
A) Integer
7
C) MIN
8
B) Groups records into summary
9
B) CONCAT
10
B) Spaces at the end
11
B) CHARINDEX
12
B) Returns characters from the beginning of the string
13
A) REPLACE
14
C) Leading and trailing spaces
15
B) Converts a string to uppercase
16
B) Extract characters from the right side of the string
17
A) GETDATE
18
A) Adds or subtracts a specified time interval to a date
19
A) YEAR
20
A) Finds the difference between two dates
21
B) GETDATE
22
A) Extracts a part of the date (e.g., month, day)
23
B) Returns the current date and time of the system
24
C) yyyy-mm-dd hh:mm:ss
25
A) DATEADD
26
A) ABS
27
A) The highest integer greater than or equal to a number
28
B) Returns the nearest whole number less than or equal to the value