MSSQL Objective Questions and Answers for Practitioners Set-2
1. Which SQL statement is used to remove all data from a table but keep the table structure intact in MSSQL?
Explanation: The "TRUNCATE TABLE" statement is used to remove all data from a table in MSSQL while keeping the table structure intact. It is faster and less resource-intensive than the "DELETE FROM" statement when removing all rows from a table.
2. What is the purpose of the SQL Server function "PARSE" or "TRY_PARSE"?
Explanation: The "PARSE" or "TRY_PARSE" function in SQL Server is used to convert a string representation of a data type to that data type. It is often used to handle data type conversions while working with user input or data from external sources.
3. What is the purpose of the SQL Server function "FORMAT"?
Explanation: The "FORMAT" function in SQL Server is used to convert a date or time value to a specific format. It allows you to specify the desired format using a format pattern.
4. What is the purpose of the SQL Server function "CROSS APPLY"?
Explanation: The "CROSS APPLY" operator in SQL Server is used to apply a specified scalar function to each row of a table expression. It allows you to call a function and return the result for each row of the outer table.
5. Which SQL statement is used to add a new row to a table in MSSQL?
Explanation: The "INSERT INTO" statement is used to add a new row to a table in MSSQL. It allows you to specify the target table and the values to be inserted into each column.
6. Which SQL statement is used to delete a database in MSSQL?
Explanation: The "DROP DATABASE" statement is used to delete a database in MSSQL. This action permanently removes the database and all its data.
7. What is the purpose of the SQL Server function "RANK()" when used with the OVER() clause?
Explanation: The "RANK()" function with the OVER() clause in SQL Server is used to assign a unique sequential number to each row in a result set. It allows you to perform ranking based on specified columns or expressions.
8. Which SQL statement is used to retrieve a random sample of rows from a table in MSSQL?
Explanation: The "SELECT ORDER BY NEWID()" statement in SQL Server is used to retrieve a random sample of rows from a table. It randomly orders the rows using the NEWID() function and then selects the specified number of rows using the "TOP" keyword.
9. What is the purpose of the SQL Server function "TRY_CONVERT"?
Explanation: The "TRY_CONVERT" 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.
10. Which SQL statement is used to return only distinct (unique) values from a column in MSSQL?
Explanation: The "SELECT DISTINCT" statement is used to return only distinct (unique) values from a column in MSSQL. It removes duplicates and returns a single instance of each distinct value.
11. What is the purpose of the SQL Server function "SESSION_CONTEXT"?
Explanation: The "SESSION_CONTEXT" function in SQL Server is used to store and retrieve session-specific information within the context of a session. It allows you to maintain stateful information between queries or stored procedures during a user's session
12. Which SQL statement is used to update data in a table with values from another table in MSSQL?
Explanation: The "MERGE INTO" statement is used to update data in a table with values from another table in MSSQL. It allows you to combine the functionality of INSERT, UPDATE, and DELETE operations based on a specified condition.
13. Which SQL statement is used to retrieve the current date and time in MSSQL?
Explanation: The "SELECT GETDATE()" statement in SQL Server is used to retrieve the current date and time from the system. It returns the current date and time as a datetime value.
14. Which SQL statement is used to create a new database in MSSQL?
Explanation: The "CREATE DATABASE" statement is used to create a new database in MSSQL. It specifies the name of the new database and any additional options, such as file locations and sizes
15. What is the purpose of the SQL Server function "CHOOSE"?
Explanation: The "CHOOSE" function in SQL Server is used to return a value from a list of expressions based on an index. The index value specifies which expression's value to return.
Rate Your Experience
: 89
: 1
Last updated in July, 2024
Quick Access