Multi-bit database field
I'm using a MSSQL database and would like to create a column that only has 4 possible values. Is there any way to define a 2-bit column? I see the bit datatype and then the next smallest is tinyint which is 1 full byte.
If there is no such field, I'd be interesting in finding out why not.
I don't see the reason for such a field.
It definately cannot be space - that's cheap today, and an economy of 6 bits is really negligible unless you have lots of rows. But in that case it will take up much space anyway, and extra 6 bits per row will again hardly make a difference.
Speed is also not a valid reason. Such bit fields would require additional manipulation to store and retrieve, making the whole process a lot slower than simply dealing with a whole byte.
Lastly, if it's about constraints, then you should use foreign keys or user-defined types (though that would require additional coding in .NET). Although I'd simply use a byte and implement the constraint in my application. Not so nice perhaps, but heck of a lot easier.
Update: Although, yes, an "enum" constraint would be useful in MSSQL. But that's again a little different than simply a 2-bit field.
What is your concern with field size? The way to implement a field domain should be using a Foreign Key constraint (MSSQL should have that).