We read your photo as:
How to fix the MySQL error "Out of range value for column 'BonusMonth'" when adding a column?
Computer Science
ScanSolve AI Answer
The error ERROR 1264 (22003): Out of range value for column 'BonusMonth' occurs because you are trying to assign the entire HireDate (which is a date value) directly to an INT column named BonusMonth. MySQL cannot implicitly convert a full date like 'YYYY-MM-DD' into a simple integer within the range of an INT data type.
You need to use the MONTH() function to extract only the month number from the HireDate column, which will then be an integer (1-12) and fit correctly into the BonusMonth column.
Here is the corrected query:
ALTER TABLE Employee ADD COLUMN BonusMonth INT AS (MONTH(HireDate)) STORED;
MONTH(HireDate): This function extracts the month number (an integer from 1 to 12) from theHireDatecolumn. This integer value is then correctly stored in theBonusMonthcolumn.
Was this helpful?
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.
Got a different question?Ask your own question
More Computer Science Questions
QHow to fix 'Out of range' error when adding a BonusMonth column to an Employee table using ALTER…QHow to fix "ERROR 1064 (42000): You have an error in your SQL syntax" when inserting into a MySQL…QHow to fix SQL syntax error when inserting data with column names containing spaces in MySQL?QHow do I fix the SQL error 'ERROR 1064 (42000): You have an error in your SQL syntax' when inserting…QHow do I fix SQL error 1064 for INSERT statements in MySQL, specifically related to column names…