MSSQL Objective Questions and Answers for Practitioners Set-3
1. Which SQL statement is used to create a new view in MSSQL?
Explanation: The "CREATE VIEW" statement is used to create a new view in MSSQL. A view is a virtual table derived from the result of a SELECT statement and can be used to simplify complex queries or provide a security layer on the underlying tables.
2. What is the purpose of the SQL Server function "FORMATMESSAGE"?
Explanation: The "FORMATMESSAGE" function in SQL Server is used to return a formatted message string with placeholders replaced by specified arguments. It is often used for generating dynamic error messages or custom messages.
3. Which SQL statement is used to rename a table in MSSQL?
Explanation
4. What is the purpose of the SQL Server function "TRY_CAST"?
Explanation: The "TRY_CAST" function in SQL Server is used to attempt to convert a string representation of a data type to that data type. If the conversion is successful, it returns the converted value; otherwise, it returns null.
5. Which SQL statement is used to retrieve the first row from a result set in MSSQL??
Explanation: The "SELECT TOP 1" statement in SQL Server is used to retrieve the first row from a result set. It allows you to limit the number of rows returned to a specified number, in this case, one.
6. What is the purpose of the SQL Server function "OFFSET" when used with the "FETCH" clause?
Explanation: The "OFFSET" function, used with the "FETCH" clause, is used for result pagination. It allows you to skip a specified number of rows (offset) and then fetch a specified number of rows from the starting point.
7. Which SQL statement is used to create a new user-defined function (UDF) in MSSQL?
Explanation: The "CREATE FUNCTION" statement is used to create a new user-defined function (UDF) in MSSQL. UDFs allow you to encapsulate custom logic and return values based on input arguments.
8. What is the purpose of the SQL Server function "INDEXPROPERTY"?
Explanation: The "INDEXPROPERTY" function in SQL Server is used to retrieve properties of an index, such as its type or status. It can be useful for analyzing and managing indexes.
9. Which SQL statement is used to grant specific privileges to a user or role in MSSQL?
Explanation: The "GRANT" statement is used to grant specific privileges or permissions to a user or role in MSSQL. It allows you to control access to database objects.
10. What is the purpose of the SQL Server function "STRING_SPLIT"?
Explanation: The "STRING_SPLIT" function in SQL Server is used to split a comma-separated string into multiple rows. Each value separated by the comma becomes a separate row in the result set.
11. Which SQL statement is used to retrieve data from multiple tables based on related columns in MSSQL?
Explanation: The "JOIN" statement is used to retrieve data from multiple tables based on related columns in MSSQL. It combines rows from two or more tables based on a related column between them.
12. What is the purpose of the SQL Server function "SESSION_ID"?
Explanation: The "SESSION_ID" function in SQL Server is used to return the ID of the current user session. It provides a unique identifier for each active user session connected to the database.
13. Which SQL statement is used to change the data type of a column in MSSQL?
Explanation: The "ALTER COLUMN" statement is used to change the data type of a column in MSSQL. It allows you to modify the data type, size, or nullability of an existing column.
14. What is the purpose of the SQL Server function "CONCAT"?
Explanation: The "CONCAT" function in SQL Server is used to concatenate strings from multiple columns or expressions. It joins the values together into a single string.
14. Which SQL statement is used to roll back a transaction and undo its changes in MSSQL?
Explanation: The "ROLLBACK" statement is used to undo the changes made by a transaction and restore the database to its state before the transaction was initiated.
Rate Your Experience
: 89
: 1
Last updated in July, 2024
Quick Access