MCQs on T-SQL Fundamentals | SQL Server

Master T-SQL Fundamentals for SQL Server with these MCQs on SELECT queries, filtering with WHERE, sorting with ORDER BY, and an introduction to Transact-SQL. Sharpen your skills with practical scenarios.


Introduction to Transact-SQL (T-SQL)

  1. What is the primary purpose of T-SQL in SQL Server?
    • A) Managing server configurations
    • B) Performing data manipulation and querying
    • C) Creating network connections
    • D) Designing user interfaces
  2. Which statement about T-SQL is correct?
    • A) It is specific to MySQL.
    • B) It is an extension of standard SQL for Microsoft SQL Server.
    • C) It replaces SQL commands entirely.
    • D) It is a programming language for web development.
  3. What is a key feature of T-SQL compared to standard SQL?
    • A) Enhanced support for procedural programming
    • B) Cross-database compatibility
    • C) Built-in machine learning functions
    • D) Exclusive use in cloud databases
  4. Which of the following is a valid T-SQL statement?
    • A) PRINT ‘Hello World!’
    • B) LOG “Hello World!”
    • C) SHOW ‘Hello World!’
    • D) DISPLAY ‘Hello World!’
  5. What is the purpose of the GO command in T-SQL?
    • A) Marks the end of a batch of T-SQL statements
    • B) Initiates a database transaction
    • C) Terminates a query immediately
    • D) Creates a backup of the database
  6. Which data type is unique to T-SQL?
    • A) MONEY
    • B) JSON
    • C) CLOB
    • D) ARRAY

Basic SELECT Queries

  1. What does the SELECT statement in T-SQL do?
    • A) Inserts data into a table
    • B) Retrieves data from a table
    • C) Deletes data from a table
    • D) Modifies existing table data
  2. Which clause is used to specify the source table in a SELECT query?
    • A) FROM
    • B) WHERE
    • C) GROUP BY
    • D) ORDER BY
  3. What happens when you execute the query SELECT * FROM Employees?
    • A) Only primary keys are retrieved.
    • B) All columns and rows from the Employees table are retrieved.
    • C) It creates a new Employees table.
    • D) It deletes all rows in the Employees table.
  4. How do you rename a column in the output of a SELECT query?
    • A) Use the AS keyword
    • B) Use the RENAME keyword
    • C) Use the MODIFY keyword
    • D) Use the COLUMN keyword
  5. What is the result of the following query?sqlCopy codeSELECT 'SQL Server' AS Technology;
    • A) Displays a syntax error
    • B) Displays the value “SQL Server” under a column named “Technology”
    • C) Inserts “SQL Server” into a table named “Technology”
    • D) Creates a table named “Technology”
  6. Which keyword is used to eliminate duplicate rows in a SELECT query?
    • A) DISTINCT
    • B) UNIQUE
    • C) TOP
    • D) LIMIT

Filtering Data with WHERE

  1. What does the WHERE clause do in a SELECT query?
    • A) Filters rows based on a condition
    • B) Sorts rows in ascending order
    • C) Groups rows with similar values
    • D) Limits the number of rows returned
  2. How do you retrieve rows where the “Salary” column is greater than 5000?
    • A) SELECT * FROM Employees WHERE Salary > 5000;
    • B) SELECT * FROM Employees HAVING Salary > 5000;
    • C) SELECT * FROM Employees GROUP BY Salary > 5000;
    • D) SELECT * FROM Employees ORDER BY Salary > 5000;
  3. What operator is used in the WHERE clause to filter rows containing NULL values?
    • A) IS NULL
    • B) = NULL
    • C) IN NULL
    • D) HAS NULL
  4. How do you use the BETWEEN operator to filter rows?
    • A) WHERE Age BETWEEN 18 AND 30
    • B) WHERE Age IS BETWEEN 18 AND 30
    • C) WHERE Age IN BETWEEN 18 AND 30
    • D) WHERE Age RANGE 18 TO 30
  5. What is the output of the query:sqlCopy codeSELECT * FROM Products WHERE Price <> 100;
    • A) All rows with Price equal to 100
    • B) All rows with Price not equal to 100
    • C) All rows with Price less than 100
    • D) An error due to invalid syntax
  6. Which operator allows you to filter rows based on multiple conditions in a WHERE clause?
    • A) AND
    • B) OR
    • C) NOT
    • D) All of the above

Sorting Data with ORDER BY

  1. What does the ORDER BY clause do?
    • A) Filters rows in a query
    • B) Sorts rows based on a specified column
    • C) Groups rows with similar values
    • D) Creates a new table
  2. Which keyword is used to sort rows in descending order?
    • A) DESC
    • B) DOWN
    • C) REVERSE
    • D) BACK
  3. What is the default sorting order in T-SQL when using ORDER BY?
    • A) Ascending
    • B) Descending
    • C) Random
    • D) No sorting is applied
  4. How do you sort by multiple columns in a SELECT query?
    • A) Use a comma to separate column names in the ORDER BY clause
    • B) Use a semicolon to separate column names
    • C) Use multiple ORDER BY clauses
    • D) Use parentheses around column names
  5. If you want to sort rows by “Department” and then by “Salary” in descending order, what query would you use?sqlCopy codeSELECT * FROM Employees ORDER BY Department, Salary DESC;
    • A) The query sorts only by Department.
    • B) The query sorts first by Department and then by Salary in descending order.
    • C) The query generates an error.
    • D) The query sorts only by Salary.
  6. How do you display the top 5 highest salaries in a table?
    • A) SELECT TOP 5 Salary FROM Employees ORDER BY Salary DESC;
    • B) SELECT * FROM Employees ORDER BY Salary ASC LIMIT 5;
    • C) SELECT Salary FROM Employees GROUP BY Salary DESC;
    • D) SELECT DISTINCT TOP 5 Salary FROM Employees;
  7. Which function can be used to generate a numbered ranking for sorted data?
    • A) ROW_NUMBER()
    • B) RANK()
    • C) DENSE_RANK()
    • D) All of the above
  8. What is the result of the following query?sqlCopy codeSELECT * FROM Orders ORDER BY DateCreated ASC;
    • A) Orders are displayed with the most recent date first.
    • B) Orders are displayed with the oldest date first.
    • C) Orders are grouped by date.
    • D) An error occurs due to invalid syntax.
  9. Can ORDER BY be used with computed columns in T-SQL?
    • A) Yes, directly in the query
    • B) No, computed columns cannot be sorted
    • C) Yes, but only with an alias
    • D) Only with numeric computed columns
  10. What happens when NULL values are sorted in ascending order?
    • A) NULL values appear first.
    • B) NULL values appear last.
    • C) NULL values are excluded.
    • D) An error occurs.
  11. Which clause can be combined with ORDER BY to limit the number of rows in the output?
    • A) TOP
    • B) WHERE
    • C) GROUP BY
    • D) DISTINCT
  12. How can you order data by both ascending and descending order in the same query?
    • A) By specifying each column’s order individually in the ORDER BY clause
    • B) By using the DESC keyword only
    • C) By running two separate queries
    • D) It is not possible

Answer Key

QnoAnswer
1B) Performing data manipulation and querying
2B) It is an extension of standard SQL for Microsoft SQL Server.
3A) Enhanced support for procedural programming
4A) PRINT ‘Hello World!’
5A) Marks the end of a batch of T-SQL statements
6A) MONEY
7B) Retrieves data from a table
8A) FROM
9B) All columns and rows from the Employees table are retrieved.
10A) Use the AS keyword
11B) Displays the value “SQL Server” under a column named “Technology”
12A) DISTINCT
13A) Filters rows based on a condition
14A) SELECT * FROM Employees WHERE Salary > 5000;
15A) IS NULL
16A) WHERE Age BETWEEN 18 AND 30
17B) All rows with Price not equal to 100
18D) All of the above
19B) Sorts rows based on a specified column
20A) DESC
21A) Ascending
22A) Use a comma to separate column names in the ORDER BY clause
23B) The query sorts first by Department and then by Salary in descending order.
24A) SELECT TOP 5 Salary FROM Employees ORDER BY Salary DESC;
25D) All of the above
26B) Orders are displayed with the oldest date first.
27C) Yes, but only with an alias
28A) NULL values appear first.
29A) TOP
30A) By specifying each column’s order individually in the ORDER BY clause

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top