Microsoft SQL Server Database Quiz Questions

Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:CAST
Current Quiz Count:45
Progress
0%
Q1
True / False

The CAST function can be used to convert a string to a date.

Q2
True / False

CAST can be used to convert a numeric value to a string data type.

Q3
True / False

The CAST function can convert a FLOAT to an INT.

Q4
True / False

CAST function can only be used for converting between numeric types.

Q5
True / False

CAST cannot be used to convert a VARCHAR to an INT if the VARCHAR contains non-numeric characters.

Q6
True / False

The CAST function will automatically round numbers when converting from FLOAT to INT.

Q7
True / False

CAST can be used to convert a CHAR to a VARCHAR.

Q8
True / False

CAST function cannot convert from VARCHAR to DATE if the format is incorrect.

Q9
True / False

The CAST function can be used to convert data types within a table but not between tables.

Q10
True / False

CAST can handle NULL values without errors during type conversion.

Q11
True / False

The CAST function will fail if you try to convert a string to a numeric type with formatting errors.

Q12
True / False

CAST cannot be used to convert a numeric type to a different numeric type, such as INT to FLOAT.

Q13
True / False

CAST can convert a DECIMAL to a CHAR, but the precision might be lost.

Q14
True / False

The CAST function is less efficient compared to the CONVERT function.

Q15
True / False

CAST can be used to convert from a FLOAT to a DATE.

Q16
Single Choice

Which of the following CAST operations is valid?

SQL Code
SELECT CAST('2024-08-02' AS DATE) AS CastedDate;
Q17
Single Choice

What is the result of casting an INT to a VARCHAR?

SQL Code
SELECT CAST(123 AS VARCHAR(10)) AS CastedValue;
Q18
Single Choice

Which SQL function would you use to convert a VARCHAR to an INT?

SQL Code
SELECT CAST('123' AS INT) AS CastedValue;
Q19
Single Choice

What happens when you CAST a NULL value?

SQL Code
SELECT CAST(NULL AS INT) AS CastedValue;
Q20
Single Choice

Which CAST operation will fail?

SQL Code
SELECT CAST('abc' AS INT) AS CastedValue;
Q21
Single Choice

What will be the result of CASTing a FLOAT to INT?

SQL Code
SELECT CAST(123.456 AS INT) AS CastedValue;
Q22
Single Choice

Which SQL keyword is used to handle conversion errors during CAST operations?

SQL Code
SELECT TRY_CAST('abc' AS INT) AS CastedValue;
Q23
Single Choice

What is the output of casting a DECIMAL to a CHAR?

SQL Code
SELECT CAST(123.456 AS CHAR(10)) AS CastedValue;
Q24
Single Choice

Which of these types can be converted using CAST?

SQL Code
SELECT CAST('2024-08-02' AS DATE) AS CastedDate;
Q25
Single Choice

Can CAST be used to convert a DATE to a VARCHAR?

SQL Code
SELECT CAST(GETDATE() AS VARCHAR(20)) AS CastedDate;
Q26
Multiple Choice

Which of the following are valid CAST operations?

SQL Code
SELECT CAST('2024-08-02' AS DATE) AS CastedDate;
SELECT CAST(123.456 AS INT) AS CastedValue;
Q27
Multiple Choice

Which SQL functions can be used in conjunction with CAST for error handling?

SQL Code
SELECT TRY_CAST('abc' AS INT) AS CastedValue;
SELECT ISNULL(CAST('123' AS INT), 0) AS CastedValue;
Q28
Multiple Choice

What are the valid uses of CAST in SQL queries?

SQL Code
SELECT CAST(column_name AS VARCHAR(20)) FROM table_name;
SELECT CAST(column_name AS DATE) FROM table_name;
Q29
Multiple Choice

Which data types can CAST convert between?

SQL Code
SELECT CAST('100' AS INT) AS IntValue;
SELECT CAST(100 AS VARCHAR(10)) AS StringValue;
Q30
Multiple Choice

Which scenarios require careful use of CAST to avoid errors?

SQL Code
SELECT CAST('invalid' AS INT);
SELECT CAST('2024-08-02' AS DATETIME);
Q31
Multiple Choice

When converting a DECIMAL to an INT using CAST, what happens to the decimal part?

SQL Code
SELECT CAST(123.456 AS INT) AS IntValue;
Q32
Multiple Choice

Which CAST operations can lead to truncation or loss of precision?

SQL Code
SELECT CAST(123.456 AS INT);
SELECT CAST('123.456' AS INT);
Q33
Multiple Choice

Which of the following will result in an error when using CAST?

SQL Code
SELECT CAST('abc' AS INT);
SELECT CAST(123.456 AS VARCHAR(5));
Q34
Multiple Choice

What is the result of CASTing a DATE to a VARCHAR?

SQL Code
SELECT CAST(GETDATE() AS VARCHAR(20)) AS DateString;
Q35
Multiple Choice

Which conversion functions provide more flexibility compared to CAST?

SQL Code
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS DateFormatted;
SELECT TRY_CONVERT(INT, '123abc') AS SafeIntValue;
Q36
Multiple Choice

Which SQL statements can effectively use CAST for data transformation?

SQL Code
SELECT CAST(some_column AS INT) FROM some_table;
SELECT CAST(another_column AS DATE) FROM another_table;
Q37
Multiple Choice

In which scenarios is CAST particularly useful in SQL Server?

SQL Code
SELECT CAST(column_name AS VARCHAR(20)) FROM table_name;
SELECT CAST(column_name AS DATE) FROM table_name;
Q38
Multiple Choice

What are the consequences of casting a string with incorrect format to a DATE?

SQL Code
SELECT CAST('2024-02-30' AS DATE) AS InvalidDate;
Q39
Multiple Choice

Which operations are safe with CAST in SQL Server?

SQL Code
SELECT CAST('123' AS INT) AS IntValue;
SELECT CAST('2024-08-02' AS DATE) AS DateValue;
Q40
Multiple Choice

Which of the following CAST scenarios might lead to precision loss?

SQL Code
SELECT CAST(123.456 AS INT);
SELECT CAST(123456789012345 AS FLOAT);
Q41
Single Choice

Which CAST function converts a string to an integer?

SQL Code
SELECT CAST('123' AS INT);
Q42
Single Choice

What is the result of casting a float to a decimal?

SQL Code
SELECT CAST(123.456 AS DECIMAL(10, 2));
Q43
Single Choice

How do you convert a date to a string format using CAST?

SQL Code
SELECT CAST(GETDATE() AS VARCHAR(10));
Q44
Single Choice

Which of the following converts a numeric value to a binary format?

SQL Code
SELECT CAST(123 AS VARBINARY);
Q45
Single Choice

What does casting a string to a datetime return when the string is invalid?

SQL Code
SELECT CAST('InvalidDate' AS DATETIME);