File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes Store flags in MySQL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Store flags in MySQL?" Watch "Store flags in MySQL?" New topic

Store flags in MySQL?

Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
what's a good variable type to store flags?
I guess you can do TEXT or VARCHAR(255) and have unique words in it, but that's a little inefficient...
int bits are a bit confusing....

Anything you can suggest?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I think you should be posting this question in JDBC forum.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61010

Quite correct... moved.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100
Since, generally flags are (on or off) or (1 or 0) or some similar pattern, I would go with tinyint. Could you be more specific?

An egg is a chicken's house!
Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
Well... If for instance I wanted a whole bunch of flags, like "user owns this, user can delete this, user can modify this, etc", would I have to create a separate column for each and every one?
I mean as I go along, I might get more and more flags, and I don't think it would be cool to have 30 columns in there, most of which would be barely used...
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

Why don't you create a FLAG_TABLE with 2 columns.
Then wherever you needed a flag, use the FLAG_ID from the FLAG_TABLE.

GenRocket - Experts at Building Test Data
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
You could use bits on an INT (my preferred approach), or a seperate "USER_SECURITY" table, with tons of fields. Either way, abstract it in your code such that it can change later on.
I agree. Here's the link:
subject: Store flags in MySQL?