Difficulty: Easy
Correct Answer: Changing a column data type from char to date
Explanation:
Introduction / Context:
Altering a column's data type requires converting all existing values to the new type. Some conversions are safe and lossless; others can fail or corrupt data if values do not conform. The question asks which change is risky and may not succeed.
Given Data / Assumptions:
Concept / Approach:
Converting from char to date requires every existing value to match a valid date format. Any malformed or ambiguous text (for example, '13/32/2022' or mixed formats) can cause the conversion or ALTER to fail. By contrast, converting numeric to char is generally safe because any numeric can be serialized to text without loss of meaning.
Step-by-Step Solution:
Verification / Alternative check:
Attempt CAST/CONVERT in a SELECT to find rows that fail; only proceed when all rows convert correctly. This reduces risk during the actual ALTER.
Why Other Options Are Wrong:
Numeric to char: string representation is straightforward and rarely fails.
Both succeed or neither succeed: overgeneralizations; success depends on data and conversion direction.
Common Pitfalls:
Ignoring time zone and locale differences in date strings; assuming the engine will auto-infer formats uniformly; failing to capture invalid rows before the ALTER.
Final Answer:
Changing a column data type from char to date
Discussion & Comments