# Best way to store this data in the database

**URL:** <https://www.ruby-forum.com/t/best-way-to-store-this-data-in-the-database/156795>\
**Category:** Rails\
**Created:** [January 3, 2009, 12:41am UTC](https://www.ruby-forum.com/t/best-way-to-store-this-data-in-the-database/156795 "2009-01-03T00:41:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [January 3, 2009, 12:41am UTC](https://www.ruby-forum.com/t/best-way-to-store-this-data-in-the-database/156795/1 "2009-01-03T00:41:05Z")

</div>

i have bunch of item properties that need to be stored in the database.  
the options for the properties are:

-unknown  
-yes  
-no

what do you think is the best way to store this data?

should i use a tinyint and only store 0, 1, 2 for the respective options  
or just use a varchar(10) and store the name of the result?

what is the usual standard?

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [January 5, 2009, 9:23pm UTC](https://www.ruby-forum.com/t/best-way-to-store-this-data-in-the-database/156795/2 "2009-01-05T21:23:58Z")

</div>

I tend these days to always use the full descriptive words - memory  
implications are small, but it is easier to directly display the value  
than have code to expand it wherever it is used. It also tends to  
make the code logic easier to follow.

tonypm

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [January 6, 2009, 6:05am UTC](https://www.ruby-forum.com/t/best-way-to-store-this-data-in-the-database/156795/3 "2009-01-06T06:05:28Z")

</div>

On Jan 5, 3:22 pm, tonypm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I tend these days to always use the full descriptive words -

Definitely not in a case like this. The set of three values here maps  
_perfectly_ to SQL-style 3-valued logic – so use it! Store this as a  
boolean value.

A larger set of strings could be stored directly in a character field  
in the database, but if the number is under 100 or so, I’d advise  
creating a separate table and simply referring to the strings by  
foreign key. This practice will avoid all sorts of data normalization  
issues. I’d never dream of storing a small number of repeating  
strings as literal text the way you’re suggesting.

> memory  
> implications are small, but it is easier to directly display the value  
> than have code to expand it wherever it is used.

Not really – especially if the application should run in more than  
one language.

> It also tends to  
> make the code logic easier to follow.

Again, not really. You have to explicitly test for == ‘yes’ rather  
than simply testing for truth or falsehood.

> tonypm

## Best,

Marnen Laibow-Koser  
removed\_email\_address@domain.invalid  
[http://www.marnen.org](http://www.marnen.org)
