Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing small negative values

Note: I realize the question here won't grossly impact performance or storage size in my database, but I'm interested hearing expert opinions (if there are any).

I'm writing an application that needs to perform an operation on a datetime value and store the resulting offset in a database. I expect the offsets to stay the same (around -3), but because the source date (the beginning date of each term) is set by a college-level committee, and because my application is dealing with contacting students at regular, predictable intervals (which would also be set by a committee) it's possible that it could be between -30 and 30.

I originally intended to store the resulting offset as a tinyint, but since it's unsigned in SQL Server 2008, I'm not sure what would work best here. Should I use a smallint, or something like a numeric(2,0)?

like image 282
jwheron Avatar asked Aug 11 '26 14:08

jwheron


2 Answers

Just use a smallint. Don't overthink it.

(Insert standard text about premature optimization here.)

like image 63
Joe Avatar answered Aug 14 '26 11:08

Joe


numeric(2,0) has a storage size of 5 bytes, vs. 2 bytes for smallint, so just use smallint.

like image 24
Jeff Ogata Avatar answered Aug 14 '26 11:08

Jeff Ogata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!