Home »
MCQs
MS SQL Server MCQs (Multiple-Choice Questions)
MS SQL Server is a relational database management system developed by Microsoft. It supports Transact-SQL (T-SQL) for querying and programming, along with features for database design, transactions, security, indexing, backup and recovery, performance tuning, and administration. These MS SQL Server MCQs cover SQL Server concepts, T-SQL, queries, joins, stored procedures, functions, triggers, indexes, transactions, security, and database administration.
MS SQL Server MCQs
Practice these MS SQL Server multiple-choice questions to test your knowledge of SQL Server development, T-SQL programming, database management, administration, and performance optimization.
List of MS SQL Server MCQs
The following MS SQL Server MCQs include answers and explanations covering both fundamental and advanced SQL Server concepts.
1. What is Microsoft SQL Server?
- A relational database management system
- A spreadsheet application
- An operating system
- A web browser
Answer: A) A relational database management system
Explanation:
Microsoft SQL Server is a relational database management system (RDBMS) used to store, retrieve, manage, and process structured data.
2. Which language is primarily used to interact with SQL Server databases?
- HTML
- T-SQL
- CSS
- XML
Answer: B) T-SQL
Explanation:
Transact-SQL (T-SQL) is Microsoft's extension of SQL and is the primary language used for querying and programming SQL Server.
3. Which SQL Server component is responsible for executing queries and managing database operations?
- Database Engine
- SQL Server Browser
- SQL Server Agent
- SQL Server Profiler
Answer: A) Database Engine
Explanation:
The SQL Server Database Engine provides the core services for storing, processing, and securing data and executing T-SQL queries.
4. Which tool provides a graphical environment for managing SQL Server and writing queries?
- SQL Server Management Studio (SSMS)
- Microsoft Paint
- Windows Media Player
- Microsoft Word
Answer: A) SQL Server Management Studio (SSMS)
Explanation:
SQL Server Management Studio (SSMS) is a Microsoft tool used to connect to SQL Server, manage databases, execute queries, and perform administrative tasks.
5. Which statement is used to create a new database in SQL Server?
- MAKE DATABASE
- CREATE DATABASE
- NEW DATABASE
- ADD DATABASE
Answer: B) CREATE DATABASE
Explanation:
The CREATE DATABASE statement creates a new SQL Server database.
6. Which statement is used to change the current database context in a T-SQL session?
- USE
- CHANGE
- SWITCH
- OPEN
Answer: A) USE
Explanation:
The USE statement changes the database context for the current connection.
7. Which statement is used to retrieve data from a SQL Server table?
- GET
- FETCH TABLE
- SELECT
- READ
Answer: C) SELECT
Explanation:
SELECT retrieves rows and columns from one or more tables, views, or other rowset sources in SQL Server.
8. Which clause filters rows before grouping in a SELECT query?
- HAVING
- WHERE
- ORDER BY
- GROUP BY
Answer: B) WHERE
Explanation:
The WHERE clause filters individual rows before the grouping operation is performed.
9. Which clause is used to sort query results?
- SORT BY
- ORDER BY
- GROUP BY
- ARRANGE BY
Answer: B) ORDER BY
Explanation:
ORDER BY sorts the result set according to one or more expressions in ascending or descending order.
10. Which keyword removes duplicate rows from a SELECT result?
- UNIQUE
- DISTINCT
- REMOVE
- FILTER
Answer: B) DISTINCT
Explanation:
DISTINCT eliminates duplicate rows from the result set based on the selected columns.
11. Which clause groups rows having the same values in specified columns?
- GROUP BY
- ORDER BY
- PARTITION BY
- COLLECT BY
Answer: A) GROUP BY
Explanation:
GROUP BY combines rows into groups so aggregate functions such as COUNT, SUM, AVG, MIN, and MAX can be applied to each group.
12. Which clause filters groups after GROUP BY has been applied?
- WHERE
- HAVING
- FILTER
- QUALIFY
Answer: B) HAVING
Explanation:
HAVING filters grouped results, commonly using aggregate expressions such as COUNT or SUM.
13. What does COUNT(*) return?
- The number of columns
- The number of rows
- The number of indexes
- The number of tables
Answer: B) The number of rows
Explanation:
COUNT(*) counts rows in the result set, including rows containing NULL values in individual columns.
14. Which aggregate function calculates the arithmetic mean of numeric values?
- MEAN()
- AVG()
- AVERAGE()
- MIDDLE()
Answer: B) AVG()
Explanation:
AVG() calculates the arithmetic average of the non-NULL values in the specified expression.
15. Which function returns the largest value in a set?
- TOP()
- MAX()
- LARGEST()
- HIGH()
Answer: B) MAX()
Explanation:
MAX() returns the maximum value of an expression among the rows being evaluated.
16. Which function returns the smallest value in a set?
- MIN()
- LOW()
- SMALLEST()
- BOTTOM()
Answer: A) MIN()
Explanation:
MIN() returns the minimum value of an expression among the rows being evaluated.
17. Which statement adds new rows to a table?
- ADD
- INSERT
- APPEND ROW
- CREATE ROW
Answer: B) INSERT
Explanation:
The INSERT statement adds new rows to a table or another target that supports insertion.
18. Which statement modifies existing rows?
- CHANGE
- MODIFY
- UPDATE
- ALTER ROW
Answer: C) UPDATE
Explanation:
UPDATE changes values in existing rows that satisfy its search condition.
19. Which statement removes selected rows from a table?
- REMOVE
- DELETE
- DROP ROW
- CLEAR
Answer: B) DELETE
Explanation:
DELETE removes rows that satisfy its WHERE condition. Without a WHERE clause, it can remove all rows from the target table.
20. Which statement removes a table definition and its data?
- DELETE TABLE
- REMOVE TABLE
- DROP TABLE
- CLEAR TABLE
Answer: C) DROP TABLE
Explanation:
DROP TABLE removes the table object and its associated data from the database.
21. Which join returns only rows that satisfy the join condition in both tables?
- LEFT JOIN
- FULL JOIN
- INNER JOIN
- CROSS JOIN
Answer: C) INNER JOIN
Explanation:
An INNER JOIN returns rows for which the join condition matches between the participating tables.
22. Which join returns all rows from the left table and matching rows from the right table?
- LEFT JOIN
- INNER JOIN
- RIGHT JOIN
- CROSS JOIN
Answer: A) LEFT JOIN
Explanation:
A LEFT JOIN returns all rows from the left input and matching rows from the right input. Unmatched right-side columns contain NULL values.
23. Which join returns all rows from both participating tables, matching them where possible?
- INNER JOIN
- FULL OUTER JOIN
- LEFT JOIN
- CROSS JOIN
Answer: B) FULL OUTER JOIN
Explanation:
A FULL OUTER JOIN returns matching rows plus unmatched rows from both sides, using NULLs where a matching row does not exist.
24. What does a CROSS JOIN produce?
- Only matching rows
- A Cartesian product of the input rowsets
- Only unmatched rows
- Only duplicate rows
Answer: B) A Cartesian product of the input rowsets
Explanation:
A CROSS JOIN combines every row from one input with every row from the other input.
25. Which physical join algorithm is commonly effective when a small input has an appropriate index on the join column?
- Nested Loops
- Cartesian Join
- Union Join
- Sort Join
Answer: A) Nested Loops
Explanation:
A Nested Loops join can be effective when one input is relatively small and the other input has an appropriate index that allows efficient matching.
26. Which operator combines the results of two queries and removes duplicate rows?
- UNION
- MERGE
- COMBINE
- JOIN
Answer: A) UNION
Explanation:
UNION combines the result sets of compatible queries and removes duplicate rows. UNION ALL retains duplicates.
27. Which operator combines query results while retaining duplicate rows?
- UNION ALL
- UNION DISTINCT
- MERGE ALL
- JOIN ALL
Answer: A) UNION ALL
Explanation:
UNION ALL concatenates compatible result sets without removing duplicate rows.
28. Which operator returns rows from the first query that are not returned by the second query?
- EXCEPT
- DIFFERENCE
- MINUS ALL
- NOT INSET
Answer: A) EXCEPT
Explanation:
EXCEPT returns distinct rows from the first query that are not also returned by the second query.
29. Which operator returns distinct rows common to both query results?
- COMMON
- INTERSECT
- INNERSET
- JOINSET
Answer: B) INTERSECT
Explanation:
INTERSECT returns distinct rows that occur in both result sets.
30. Which keyword is commonly used for pattern matching in SQL Server?
- MATCH
- LIKE
- PATTERN
- SEARCH
Answer: B) LIKE
Explanation:
LIKE performs pattern matching against character expressions, commonly using wildcards such as % and _.
31. In a LIKE pattern, what does the percent sign (%) represent?
- Exactly one character
- Zero or more characters
- Only numeric characters
- A space character
Answer: B) Zero or more characters
Explanation:
In SQL Server LIKE patterns, % matches a string of zero or more characters.
32. In a LIKE pattern, what does the underscore (_) wildcard represent?
- Zero or more characters
- Exactly one character
- Only a numeric character
- An entire word
Answer: B) Exactly one character
Explanation:
The underscore wildcard represents a single character in a LIKE pattern.
33. What does the IS NULL predicate test?
- Whether a value is zero
- Whether an expression evaluates to NULL
- Whether a value is an empty string only
- Whether a column contains duplicate values
Answer: B) Whether an expression evaluates to NULL
Explanation:
IS NULL checks whether an expression contains the SQL NULL value. Equality comparisons such as = NULL should not be used for this purpose.
34. Which function returns the first non-NULL expression from its arguments?
- ISNULL
- COALESCE
- NULLIF
- FIRSTNULL
Answer: B) COALESCE
Explanation:
COALESCE evaluates its expressions in order and returns the first one that is not NULL.
35. Which SQL Server function accepts two expressions and returns the replacement value when the first expression is NULL?
- ISNULL
- NULLIF
- COALESCEONLY
- REPLACE_NULL
Answer: A) ISNULL
Explanation:
ISNULL checks an expression and returns the replacement value when that expression evaluates to NULL.
36. Which function returns NULL when its two expressions are equal?
- NULLIF
- ISNULL
- COALESCE
- NULLMATCH
Answer: A) NULLIF
Explanation:
NULLIF returns NULL when its two expressions are equal; otherwise, it returns the first expression.
37. Which T-SQL function returns the current date and time of the SQL Server system?
- NOW()
- GETDATE()
- CURRENT_TIME_ONLY()
- SERVERDATE()
Answer: B) GETDATE()
Explanation:
GETDATE() returns the current database system date and time as a datetime value.
38. Which SQL Server function returns the current date and time with a datetime2 value and higher fractional-second precision than GETDATE()?
- SYSDATETIME()
- GETDATEONLY()
- SERVERTIME()
- CURRENTDATETIME()
Answer: A) SYSDATETIME()
Explanation:
SYSDATETIME() returns the current system date and time as a datetime2 value with greater fractional-second precision than GETDATE().
39. Which function can return a portion of a date such as year, month, or day?
- DATEPART()
- DATESECTION()
- GETPART()
- DATEXTRACTONLY()
Answer: A) DATEPART()
Explanation:
DATEPART() returns an integer representing the specified datepart of a date value.
40. Which function adds a specified number of date units to a date?
- DATEADD()
- ADD_DATE()
- DATEPLUS()
- INCREMENTDATE()
Answer: A) DATEADD()
Explanation:
DATEADD() adds a specified number of units such as days, months, or years to a date expression.
41. Which statement is used to create a table?
- BUILD TABLE
- CREATE TABLE
- NEW TABLE
- MAKE TABLE
Answer: B) CREATE TABLE
Explanation:
CREATE TABLE defines a new table and its columns, data types, and constraints.
42. Which constraint uniquely identifies each row in a table?
- FOREIGN KEY
- PRIMARY KEY
- CHECK
- DEFAULT
Answer: B) PRIMARY KEY
Explanation:
A primary key uniquely identifies rows in a table and does not allow NULL values in its key columns.
43. What is the purpose of a foreign key?
- To enforce a relationship between related tables
- To encrypt all table data
- To automatically create indexes on every column
- To generate random values
Answer: A) To enforce a relationship between related tables
Explanation:
A foreign key references a key in another table and helps enforce referential integrity between related data.
44. Which constraint prevents duplicate values in a column or set of columns?
- UNIQUE
- CHECK
- DEFAULT
- IDENTITY
Answer: A) UNIQUE
Explanation:
A UNIQUE constraint prevents duplicate key values in the constrained column or combination of columns.
45. Which constraint restricts values according to a Boolean expression?
- CHECK
- DEFAULT
- UNIQUE
- IDENTITY
Answer: A) CHECK
Explanation:
A CHECK constraint requires inserted or updated values to satisfy a specified logical condition.
46. What is the purpose of a DEFAULT constraint?
- To supply a value when an insert does not provide one for the column
- To make a column the primary key
- To prevent all NULL values
- To create a clustered index
Answer: A) To supply a value when an insert does not provide one for the column
Explanation:
A DEFAULT constraint supplies a predefined value when an INSERT statement does not specify a value for that column, subject to the column and statement conditions.
47. What does the IDENTITY property commonly provide?
- Automatically generated numeric values for a column
- Automatic encryption of a column
- Automatic foreign-key creation
- Automatic table deletion
Answer: A) Automatically generated numeric values for a column
Explanation:
The IDENTITY property generates numeric values according to a defined seed and increment. It is commonly used for surrogate key columns.
48. Which SQL Server data type is designed to store variable-length Unicode character data?
- VARCHAR
- NVARCHAR
- CHAR
- BINARY
Answer: B) NVARCHAR
Explanation:
NVARCHAR stores variable-length Unicode character data and is commonly used when Unicode text must be supported.
49. Which data type is appropriate for storing an exact numeric value with defined precision and scale?
- FLOAT
- DECIMAL
- REALTEXT
- VARCHAR
Answer: B) DECIMAL
Explanation:
DECIMAL, also known as NUMERIC, stores fixed-precision and fixed-scale numeric values.
50. Which SQL Server data type stores a Boolean-like value using 0, 1, or NULL?
- BOOLEAN
- BIT
- BOOL
- LOGICAL
Answer: B) BIT
Explanation:
SQL Server uses the BIT data type for Boolean-like values, commonly represented as 0 or 1, and it can also contain NULL.
51. What is a view in SQL Server?
- A virtual table defined by a query
- A physical backup file
- A database server instance
- A transaction log
Answer: A) A virtual table defined by a query
Explanation:
A view is a database object defined by a SELECT query. A standard view stores the query definition rather than an independent copy of the result data.
52. Which statement creates a view?
- CREATE VIEW
- MAKE VIEW
- NEW VIEW
- DEFINE VIEW ONLY
Answer: A) CREATE VIEW
Explanation:
CREATE VIEW defines a view based on a SELECT statement.
53. What is an indexed view?
- A view with an index created on it after meeting SQL Server requirements
- A view that cannot contain a SELECT statement
- A view used only for backups
- A temporary table
Answer: A) A view with an index created on it after meeting SQL Server requirements
Explanation:
An indexed view is a view for which an index has been created. SQL Server imposes specific requirements on the view definition and indexing process.
54. What is a stored procedure?
- A named collection of T-SQL statements stored in the database
- A physical database file
- An index type
- A transaction isolation level
Answer: A) A named collection of T-SQL statements stored in the database
Explanation:
A stored procedure is a programmable database object containing T-SQL statements that can be executed by name or through other mechanisms.
55. Which statement creates a stored procedure?
- CREATE PROCEDURE
- CREATE METHOD
- MAKE PROCEDURE
- NEW PROCEDURE
Answer: A) CREATE PROCEDURE
Explanation:
CREATE PROCEDURE defines a stored procedure in SQL Server.
56. Which keyword is used to declare a local T-SQL variable?
- DECLARE
- DEFINE
- VAR
- LOCALIZE
Answer: A) DECLARE
Explanation:
T-SQL uses DECLARE to define local variables, such as DECLARE @Total INT;.
57. Which syntax correctly declares an integer variable in T-SQL?
DECLARE @Count INT;
DECLARE Count AS INTEGER;
VAR @Count INTEGER;
CREATE @Count INT;
Answer: A) DECLARE @Count INT;
Explanation:
T-SQL local variables are prefixed with @ and are declared using DECLARE followed by the variable name and data type.
58. Which statement can assign a value to a T-SQL variable?
- SET
- ASSIGN ONLY
- PUT
- VALUE
Answer: A) SET
Explanation:
SET can assign a value to a local T-SQL variable, for example SET @Count = 10;.
59. Which SQL Server object can return a scalar value or a table result based on its definition?
- User-defined function
- Index
- Constraint
- Database file
Answer: A) User-defined function
Explanation:
SQL Server supports user-defined functions, including scalar-valued and table-valued functions.
60. Which type of user-defined function returns a table?
- Table-valued function
- Scalar-only function
- Aggregate-only function
- View-valued function
Answer: A) Table-valued function
Explanation:
A table-valued function returns a table result and can be used in queries as a table expression.
61. What is a trigger in SQL Server?
- A special type of stored procedure that automatically executes in response to specified events
- A database backup file
- An index maintenance command
- A query execution plan
Answer: A) A special type of stored procedure that automatically executes in response to specified events
Explanation:
Triggers are special programmable objects that execute automatically when supported events occur, such as INSERT, UPDATE, or DELETE operations.
62. Which trigger type executes after a DML operation has completed?
- AFTER trigger
- BEFORE trigger
- PRE trigger
- START trigger
Answer: A) AFTER trigger
Explanation:
An AFTER trigger executes after the triggering DML statement has successfully completed its relevant action.
63. Which trigger type is commonly used to intercept an INSERT, UPDATE, or DELETE operation before the operation completes?
- INSTEAD OF trigger
- AFTER trigger
- BEFORE ONLY trigger
- PRECOMMIT trigger
Answer: A) INSTEAD OF trigger
Explanation:
An INSTEAD OF trigger executes instead of the triggering operation, allowing custom logic to control what happens when the event occurs.
64. Which logical tables are available inside a DML trigger for accessing affected rows?
- inserted and deleted
- new and old only
- current and previous
- source and target
Answer: A) inserted and deleted
Explanation:
SQL Server DML triggers can use the inserted and deleted logical tables to access row versions associated with the triggering operation.
65. What is a Common Table Expression (CTE) in SQL Server?
- A temporary named result set defined within the execution scope of a statement
- A permanent physical table
- A database backup
- A type of index
Answer: A) A temporary named result set defined within the execution scope of a statement
Explanation:
A CTE is defined using WITH and provides a named query expression that can be referenced by the statement immediately following it. Recursive CTEs can also reference themselves.
66. Which keyword begins a Common Table Expression?
- WITH
- CTE
- USING
- DEFINE
Answer: A) WITH
Explanation:
A CTE begins with the WITH keyword, followed by the CTE name and its query definition.
67. What is a recursive CTE useful for?
- Querying hierarchical or recursively related data
- Creating database backups
- Creating indexes automatically
- Changing server authentication mode
Answer: A) Querying hierarchical or recursively related data
Explanation:
Recursive CTEs can repeatedly execute a query expression and are commonly used for hierarchical structures such as employee-manager relationships.
68. Which clause is used with window functions to define how rows are divided into groups for calculation?
- PARTITION BY
- GROUP WINDOW
- WINDOW GROUP
- SEGMENT BY
Answer: A) PARTITION BY
Explanation:
PARTITION BY divides rows into logical partitions within an OVER clause, allowing a window function to calculate results separately for each partition.
69. Which function assigns sequential row numbers within each partition?
- ROW_NUMBER()
- ROW_INDEX()
- SEQUENCE_NUMBER()
- NUMBER_ROWS()
Answer: A) ROW_NUMBER()
Explanation:
ROW_NUMBER() assigns a sequential integer to rows within each partition according to the ordering specified in its OVER clause.
70. What is a key difference between RANK() and ROW_NUMBER()?
- RANK() can assign the same rank to tied rows, while ROW_NUMBER() assigns distinct sequential numbers
- ROW_NUMBER() cannot use ORDER BY
- RANK() can only be used with text columns
- They always produce identical results
Answer: A) RANK() can assign the same rank to tied rows, while ROW_NUMBER() assigns distinct sequential numbers
Explanation:
RANK() gives tied rows the same rank and leaves gaps after ties, while ROW_NUMBER() assigns a distinct sequence number to each row according to the specified ordering.
71. Which function assigns the same rank to tied rows without leaving gaps in the ranking sequence?
- DENSE_RANK()
- ROW_NUMBER()
- RANK_GAP()
- GROUP_RANK()
Answer: A) DENSE_RANK()
Explanation:
DENSE_RANK() assigns the same rank to tied rows and does not leave gaps between ranking values.
72. Which clause defines the ordering of rows for a window function?
- ORDER BY inside OVER()
- SORT BY outside SELECT
- WINDOW ORDER
- RANK BY
Answer: A) ORDER BY inside OVER()
Explanation:
Window functions use ORDER BY within the OVER clause to define the logical order in which rows are evaluated.
73. Which statement starts an explicit transaction in T-SQL?
- BEGIN TRANSACTION
- START DATABASE
- OPEN TRANSACTION
- CREATE TRANSACTION
Answer: A) BEGIN TRANSACTION
Explanation:
BEGIN TRANSACTION starts an explicit transaction in T-SQL.
74. Which statement permanently commits the changes made by a transaction?
- COMMIT TRANSACTION
- SAVE TRANSACTION
- APPLY TRANSACTION
- END DATABASE
Answer: A) COMMIT TRANSACTION
Explanation:
COMMIT TRANSACTION makes the changes performed within the transaction permanent, subject to the transaction's execution context.
75. Which statement rolls back a transaction?
- UNDO TRANSACTION
- ROLLBACK TRANSACTION
- REVERSE TRANSACTION
- CANCEL DATABASE
Answer: B) ROLLBACK TRANSACTION
Explanation:
ROLLBACK TRANSACTION reverses the transaction's changes according to the transaction and savepoint scope.
76. Which statement creates a transaction savepoint?
- SAVE TRANSACTION
- CREATE SAVEPOINT
- MARK TRANSACTION
- CHECKPOINT TRANSACTION
Answer: A) SAVE TRANSACTION
Explanation:
SAVE TRANSACTION establishes a savepoint within a transaction to which a partial rollback can be performed.
77. Which isolation level prevents dirty reads by requiring a transaction to read committed data?
- READ COMMITTED
- READ UNCOMMITTED
- NO LOCK
- UNSAFE READ
Answer: A) READ COMMITTED
Explanation:
READ COMMITTED prevents a transaction from reading data that another transaction has modified but not committed.
78. Which isolation level permits dirty reads?
- READ COMMITTED
- READ UNCOMMITTED
- REPEATABLE READ
- SERIALIZABLE
Answer: B) READ UNCOMMITTED
Explanation:
READ UNCOMMITTED allows a transaction to read data that may have been modified by another transaction but not yet committed.
79. Which isolation level provides the strictest standard locking-based isolation among the traditional SQL Server isolation levels?
- READ UNCOMMITTED
- READ COMMITTED
- REPEATABLE READ
- SERIALIZABLE
Answer: D) SERIALIZABLE
Explanation:
SERIALIZABLE provides the strongest traditional transaction isolation by preventing phenomena such as phantom reads through stronger locking behavior.
80. What is a deadlock?
- A situation where two or more transactions wait for resources held by one another
- A completed transaction
- A disabled database
- A failed backup file
Answer: A) A situation where two or more transactions wait for resources held by one another
Explanation:
A deadlock occurs when transactions form a cycle of resource dependencies. SQL Server detects deadlocks and chooses one transaction as the victim so processing can continue.
81. What is an index primarily used for?
- Improving data access performance for suitable queries
- Encrypting database backups
- Replacing every table constraint
- Storing stored procedures
Answer: A) Improving data access performance for suitable queries
Explanation:
Indexes provide data access structures that can allow SQL Server to locate qualifying rows more efficiently for suitable queries, although indexes also introduce storage and maintenance costs.
82. What is a clustered index?
- An index that determines the logical order of rows in the table's data pages
- An index that can only contain text data
- An index that exists only in temporary tables
- An index that stores only NULL values
Answer: A) An index that determines the logical order of rows in the table's data pages
Explanation:
A clustered index organizes the table's data rows according to the clustered index key. A table can have only one clustered index.
83. How many clustered indexes can a standard SQL Server table have?
- One
- Two
- Ten
- Unlimited
Answer: A) One
Explanation:
A table can have only one clustered index because the data rows can have only one physical ordering structure.
84. What is a nonclustered index?
- A separate index structure containing keys and row locators
- A backup copy of the database
- A table without columns
- A transaction log record
Answer: A) A separate index structure containing keys and row locators
Explanation:
A nonclustered index is stored separately from the table's data rows and contains index keys plus information used to locate the corresponding rows.
85. Can a SQL Server table have multiple nonclustered indexes?
- Yes
- No
- Only one per database
- Only one per schema
Answer: A) Yes
Explanation:
A table can have multiple nonclustered indexes. However, excessive indexing can increase storage requirements and the cost of INSERT, UPDATE, and DELETE operations.
86. What is a covering index?
- An index that contains all columns needed by a particular query
- An index that covers an entire database backup
- An index that encrypts table data
- An index that contains only primary keys
Answer: A) An index that contains all columns needed by a particular query
Explanation:
A covering index contains the key and included columns necessary for a query, allowing SQL Server to satisfy the query from the index without needing additional access to the base table for those columns.
87. Which option adds non-key columns to a nonclustered index?
- INCLUDE
- ADD COLUMN
- COVER
- STORE
Answer: A) INCLUDE
Explanation:
The INCLUDE clause adds non-key columns to a nonclustered index, which can help create a covering index without making those columns part of the index key.
88. What does index fragmentation generally indicate?
- Logical ordering of index pages has become less optimal
- The database has no tables
- All queries are invalid
- The transaction log is empty
Answer: A) Logical ordering of index pages has become less optimal
Explanation:
Index fragmentation can occur as data changes cause pages to become less logically ordered or less densely packed. Appropriate index maintenance depends on the level and type of fragmentation and workload.
89. Which statement can rebuild an index?
- ALTER INDEX ... REBUILD
- RECREATE INDEX ONLY
- BUILD INDEX NOW
- RESET INDEX
Answer: A) ALTER INDEX ... REBUILD
Explanation:
SQL Server supports ALTER INDEX ... REBUILD for rebuilding indexes and can perform additional operations depending on the specified options and SQL Server edition/version.
90. What is the Query Optimizer responsible for?
- Choosing an execution strategy for a query
- Creating user passwords
- Backing up all databases automatically
- Changing table names
Answer: A) Choosing an execution strategy for a query
Explanation:
The SQL Server Query Optimizer evaluates possible execution strategies and selects an execution plan based on estimated costs and available information.
91. What is an execution plan?
- A representation of how SQL Server plans to execute a query
- A backup schedule
- A database security policy
- A table definition
Answer: A) A representation of how SQL Server plans to execute a query
Explanation:
An execution plan describes the operators and strategy SQL Server uses or intends to use to execute a query.
92. Which system view can provide information about databases on a SQL Server instance?
- sys.databases
- sys.tables_only
- system.database_list
- master.database_catalog
Answer: A) sys.databases
Explanation:
sys.databases is a catalog view that provides information about databases accessible on the SQL Server instance.
93. Which system catalog view provides information about tables in the current database?
- sys.tables
- sys.objects_only_tables
- database.tables
- system.tables_list
Answer: A) sys.tables
Explanation:
sys.tables provides metadata about user tables and related table properties in the current database.
94. Which database is primarily used by SQL Server to store system-level information and metadata?
- master
- tempdb
- model
- msdb
Answer: A) master
Explanation:
The master database contains system-level information such as server configuration metadata, login information, and information about databases.
95. Which SQL Server system database is used for temporary objects and intermediate results?
- master
- tempdb
- model
- msdb
Answer: B) tempdb
Explanation:
tempdb is used for temporary tables, table variables in relevant execution contexts, worktables, version-store activity, and other temporary database-engine operations.
96. Which system database provides the template used when creating new databases?
- model
- master
- tempdb
- msdb
Answer: A) model
Explanation:
The model database acts as a template for new databases. Objects and settings placed in model can influence newly created databases.
97. Which system database is commonly associated with SQL Server Agent jobs and other scheduling-related information?
- msdb
- master
- tempdb
- model
Answer: A) msdb
Explanation:
The msdb database stores information used by SQL Server Agent and other SQL Server components, including jobs and schedules.
98. Which database file normally stores the transaction log?
- .mdf
- .ndf
- .ldf
- .bak
Answer: C) .ldf
Explanation:
SQL Server transaction log files normally use the .ldf extension. Primary data files commonly use .mdf, while secondary data files commonly use .ndf.
99. Which backup type contains all data needed to restore the database to the point represented by that backup, subject to the backup and recovery chain?
- Full database backup
- Transaction log backup only
- File-name backup
- Index backup
Answer: A) Full database backup
Explanation:
A full database backup contains a complete backup of the database data needed as a base for restoration. Additional differential or log backups may be required depending on the desired recovery point.
100. Consider the following SQL Server query:
WITH RankedEmployees AS
(
SELECT
EmployeeID,
EmployeeName,
Department,
Salary,
ROW_NUMBER() OVER
(
PARTITION BY Department
ORDER BY Salary DESC
) AS RowNum
FROM Employees
)
SELECT EmployeeID, EmployeeName, Department, Salary
FROM RankedEmployees
WHERE RowNum = 1;
What does this query return?
- The highest-paid employee from each department
- The highest-paid employee from the entire company only
- Every employee sorted by salary
- The lowest-paid employee from each department
Answer: A) The highest-paid employee from each department
Explanation:
The CTE calculates ROW_NUMBER() separately for each Department because of PARTITION BY Department. Within each department, employees are ordered by Salary in descending order, so RowNum = 1 identifies the highest-paid employee in each department. This combines a CTE with a window function to solve a common top-per-group query pattern.
Advertisement
Advertisement