Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:52:28+00:00 2026-05-27T13:52:28+00:00

I need to store 5 boolean values in 1 table. Each value could be

  • 0

I need to store 5 boolean values in 1 table.
Each value could be stored as tinyint(4). So, there are 5 tinyint(4).
I’m thinking of putting 5 boolean values in one tinyint(4).
I believe, everybody knows even better than me, 5 bits could be saved in 1 byte with no problem:)
The first value could be stored as 0(false) or 1(true), the second as 0(false) or 2(true), the third as 0 or 4, fourth as 0 or 8, fifth as 0 or 16.
So, if we store the sum of that values in tinyint(4), we exactly know 5 Boolean values.

    For example, stored 21 -> 16 + 4+1.
So, if 21 is stored, we know that:
    Fifth=true
    Fourth=false
    Third=true
    Second=false
    First=true.

My question is:
Does it make sense to keep only 1 variable? We win db volume (bytes) and performance (4 columns less, but that’s only 4 bytes whereas you have actually used varchar(1000) in the same table), but every time we have to “extract” a proper Boolean value from “sum” using php function, and that happens often (let’s say when a user presses the button).
Does it all make sense to store Boolean values as a sum in 1 column or not, so you have 7 columns instead of 11?

That values, that’s clear (because that table has much more rows that just 2), are not keys.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:52:28+00:00Added an answer on May 27, 2026 at 1:52 pm

    Don’t do this — unless the value is a single “opaque” external data-type, such as a Enum of flags — if the columns will ever be used in a query or will ever be used outside of said “opaque” type: use discrete/separate fields. (Of the correct type, as jmucchiello and MarkR noted in their answers.)

    Trying “for performance” here will just make you loath databases — and this one in particular — when you have to “fix” it or work around the ugly scheme later. (If you have a performance problem you’ll know it … and know enough to run a performance analysis before asking.) Donald Knuth was right when he pointed out that 97% of stuff Just Doesn’t Matter. So make it pretty and let the database do what it feels like doing.

    Happy coding.


    If I sound animated above, it’s because I’m trying help others avoid the same mistakes I’ve done run into 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every now and then there is a need to store a boolean value only
I need a dictionary but I also need to store a boolean value about
I need to store a list of key value pairs of (integer, boolean) in
How can I store a boolean value in each row of a UITableview. I
I have id values for products that I need store. Right now they are
I need to store products for an e-commerce solution in a database. Each product
I need to store phone numbers in a table. Please suggest which datatype should
I need to store user entered changes to a particular table, but not show
I need to store boolean data in Windows Azure. I want to make the
I have a set of five boolean values. If more than one of these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.