NYCPHP Meetup

NYPHP.org

[nycphp-talk] Database, table, and column naming schemes

Matt Juszczak matt at atopia.net
Sat Sep 19 12:43:58 EDT 2009


Kristina,

While we're on this subject, I thought I would ask another pending 
question I have related to this.

I need to store a bunch (and by a bunch, I mean about 30-40) binary 
true/false values in my database.

In the past, I would do something like this:

CREATE TABLE........... (
 				is_active tinyint(1) default 1,
 				is_friend tinyint(1) default 1,
 				is_something tinyint(1) default 1,
 				is_something_else tinyint(1) default 1,
 				......
 			);

But that table would really get large if I had 30-40 extra columns in it. 
The other option was that I was considering a bit string:


CREATE TABLE......... (
 				permissions mediumint(11) default 0
);

INSERT INTO permissions (permissions) values (7);

Since there are 3 bits that make up the integer "8" (or 0 - 7):

1,2,4

This would mean that I could store 3 combinations of permissions, but it 
would be an integer.

This could get even more complex if I had 30-40, as I could do a really 
large hex string, or just store the actual bit string:


aef214  <--- one value
11000110111011 <-- or something like that


Thoughts?

-Matt



More information about the talk mailing list