Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
This question sounds like it is the tip of an iceberg for a bigger question. Exactly what efficiencies or benefits were you given for using TINYINT versus BIT?
If your choice is a single BIT vs a single TINYINT column, then it makes no difference - the minimum unit of storage is a byte. But if you have 3 true/false conditions (for example), you can have 3 BIT fields which will still store 1 byte per record. (3 TINYINT columns would use 3 bytes per record)
And, of course, less space per record is advantageous because then you can fit more records per Page, lower disk i/o, etc. For small scale projects, you'll likely never notice a difference. On a larger scale, 1 or 2 bytes per record can have a much larger impact.
What exact "best practice"? What supporting documentation or business need motivated this statement?I wasn't really given any real reasons other than that someone said it's best practice to do so.
I've asked myself this same question and Google'd around trying to find anything. I'm as skeptical as you are of this so-called "best practice". I don't feel like I ever get straight answers when I ask about it, and the other person is more senior than I at our office. Before I go getting myself into a debate over the use of BIT vs TINYINT, I thought I'd ask around to see if anybody knows/read/heard anything remotely related to this topic.What exact "best practice"? What supporting documentation or business need motivated this statement?
Regarding the business needs, the column is only meant to hold TRUE/FALSE or YES/NO values so I don't see any reason why shouldn't be using BIT data types.If a column is a true/false or yes/no scenario, then BIT would likely be appropriate; if more than two values are possible, then TINYINT could be appropriate. However... it's important to consider the business needs in addition to query and database schema optimizations; so treat that first sentence as a guidelines and not a blanket statement rule. Also consider that BIT is more self-documenting than TINYINT. And as a general rule, I try to avoid allowing NULLs for BIT columns.
Maybe there's something to this last part here that the other person isn't able to explain to me. We won't need to do any mathemtical computations on the field so that's a moot point for us, but we do group on BIT fields. I just tried running an aggregate query based on the BIT field and it seems to work fine. However, is grouping on a BIT field maybe inefficient because it needs to auto-cast the data type into an INT/TINYINT first?Some other technical thoughts...
BIT fields can be used for filtering and ordering, but cannot be used for math calculations and aggregations. An example would be that "WHERE MyBitField=1" and "ORDER BY MyBitField" would work, but "MyBitField + 1" and "GROUP BY MyBitField" would not work (unless you wrapped MyBitField in a CAST statement to another numeric type, but that's getting a little off-topic). Plus, there is the space saving consideration with BIT over TINYINT.
Regarding the business needs, the column is only meant to hold TRUE/FALSE or YES/NO values so I don't see any reason why shouldn't be using BIT data types.
Sorry if you feel I'm asking dumb questions, but I'm just trying to find ANY reason/argument for using TINYINT instead of BIT. If nobody can come up with an answer, I feel I can build a stronger case for using the BIT data types.
You should have asked the question of the person who offered you this advice.I've asked myself this same question and Google'd around trying to find anything.
And what reason do they give for their changes? Indeed, you said you've asked in the past, but you didn't think you were getting straight answers. Why not? What answers did you get, and what, in particular, bothered you about them?These people are not in any better shoes to be able to better define the business needs than me so their reasons are purely technical regarding BIT vs TINYINT.