MSSQL Objective Questions and Answers for Beginners Set-3
1. What is a foreign key in a database table?
Explanation: A foreign key is a column or a combination of columns in a table that references the primary key of another table. It establishes a link between the two tables and enforces referential integrity. This means that the values in the foreign key column(s) must exist in the referenced table's primary key column(s).
2. Which SQL data type would you use to store a fixed-length string of characters?
Explanation: The CHAR data type is used to store fixed-length strings of characters. When you define a CHAR column, you need to specify the maximum length of the string, and any stored values will be padded with spaces to fill the fixed length.
3. What is the purpose of the SQL BETWEEN operator?
Explanation: The SQL BETWEEN operator is used to filter rows based on a specified range of values for a column. It is often used in the WHERE clause with the AND keyword to specify a lower and upper boundary for the values to be included in the result set.
4. What is the purpose of the SQL NULL value?
Explanation: In SQL, NULL is a special value that represents the absence of data or an unknown value. It is different from zero or an empty string. Columns that allow NULL values can have missing or unknown data.
5. What is the purpose of the SQL TOP clause?
Explanation: The SQL TOP clause is used to limit the number of rows returned by a SELECT statement. It allows you to specify a numeric value to determine how many rows should be included in the result set.
6. Which SQL data type would you use to store large text data, such as paragraphs or documents?
Explanation: The TEXT data type is used to store large amounts of text data in SQL Server. It can handle large paragraphs, documents, or any other long-form textual content.
7. What is the purpose of the SQL LIKE operator?
Explanation: The SQL LIKE operator is used to filter rows based on a specified pattern or string match. It is often used with wildcard characters, such as "%" (matches any sequence of characters) or "_" (matches any single character), to search for specific patterns within the data.
8. What is the purpose of the SQL AVG() function?
Explanation: The SQL AVG() function is an aggregate function used to calculate the average value of a numeric column. It adds up all the values in the column and divides the sum by the number of rows to determine the average.
9. Which SQL data type would you use to store a date and time value in MSSQL?
Explanation: The SQL DATE data type is used to store date values in MSSQL. It stores the date without the time portion.
10. What is the purpose of the SQL SUM() function?
Explanation: The SQL SUM() function is used to calculate the sum of all the values in a column of numeric data. It is often used with the SELECT statement and can be combined with the GROUP BY clause to find the sum within groups.
11. Which SQL data type would you use to store monetary values in MSSQL?
Explanation: The SQL DECIMAL data type is used to store exact numeric values, such as monetary values, with a fixed number of digits before and after the decimal point. It is commonly used to maintain accuracy in financial calculations.
12. What is the purpose of the SQL AS keyword in a SELECT statement?
Explanation: The SQL AS keyword is used in the SELECT statement to assign an alias to a column or a table. This alias provides a different name to the column or table in the result set, making the output more readable and concise.
13. What is the purpose of the SQL UNION operator?
Explanation: The SQL UNION operator is used to combine the result sets of two or more SELECT statements into a single result set. It allows you to merge rows from different tables, but the number and data types of columns in each SELECT statement must match.
14. What is the purpose of the SQL CASE statement?
Explanation: The SQL CASE statement is used to perform conditional logic in SQL queries. It allows you to evaluate multiple conditions and return different values based on those conditions, similar to the "IF-THEN-ELSE" logic in other programming languages.
15. What is the purpose of the SQL CHECK constraint?
Explanation: The SQL CHECK constraint is used to enforce a condition on the data being inserted or updated in a column. It ensures that the data meets a specific condition defined by the CHECK constraint.
Rate Your Experience
: 89
: 1