I do realize that it is better for a column to be an Integer if one has to perform mathematical calculations on it.
I probably have to perform mathematical calculations on the "year" column but minimally. So would it be better to store it as a String or Integer?
Thanks.
Integer is a numeric value, while String is a character value represented in quotes.
So, we should use integer data type for age.
If you need to store a year in the database, you would either want to use an Integer datatype (if you are dead set on only storing the year) or a DateTime datatype (which would involve storing a date that basically is 1/1/1990 00:00:00 in format).
SQL Server YEAR() function overviewThe YEAR() function returns an integer value which represents the year of the specified date.
Save it as an integer.
While there may be some application where you are reading and serving this data so frequently that the int->string conversion is a problem... that is going to be an edge case.
On the other side
If you are not expecting your YEAR
variable to ever contain non-digit values then yes you should store it as a number.
I would not store it as INT
since I doubt year will reach the limit that INT
has to offer. I would save it as SMALLINT
or even TINYINT
either should be unsigned
.
SMALLINT UNSIGNED
gives you max value of 65535
, unless you are storing years that exceed the year 65535
this should suffice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With