Issue with SQL Non-negatives and TinyInt

Viewed 1194

So in this assignment I was given the specific instruction:

"Add a new driver_age column to the drivers table with a TINYINT(2) data type that must not be a negative value and can’t be null."

So I put the following code into the system:

`ALTER TABLE EPDriver.drivers ADD driver_age TINYINT(2) NOT NULL;`

I keep getting an error from the system saying:

[Error]: Task 2. Expected: Add a new driver_age column to the drivers table with the specified data type. Try again.

This is done in Codio which auto-grades my code. I think it has something to do with TINYINT being able to go negative but now I don't know how to correct that parameter.

1 Answers

You can add UNSIGNED attribute to the TINYINT(2) so that it can never be negative.

ALTER TABLE EPDriver.drivers ADD driver_age TINYINT(2) UNSIGNED NOT NULL;
Related