Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Boolean

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I know this is a somewhat trivial questoin, but I have actually done my research, and I do have it implemented, I'm just looking for a better way...

(using mySQL 4.0.12)

No pre-defined boolean type in mySQL...

I thought I remembered reading somewhere that I could store booleans in mySQL by flipping a single bit, thereby saving a ton of space... can't seem to see how to do this though... instead I'm using a tiny-int, but if I'm not mistaken in my quick binary math, that's still 8 bits.

Thanks for any help.

-Rob
 
Even if you could flip one bit, you'd have to flip one bit of an existing column type -- and of those, tinyint is the smallest available.

If you had more than one piece of yes/no data to store, you could share a single column. You can perform bitwise logical operations on the tinyint.

You could also declare the column a set. Want the best answers? Ask the best questions: TANSTAAFL!
 
I meant, I thought BIT was a column type that could be used... in fact I see it on the list in the mySQL docs, but I don't see anything about it or how it's used etc.

-Rob
 
Thanks, I'm still getting familar with the docs... must've been a faulty memory of mine.

Thanks for the info.

-Rob
 
Right, when storing multiple truth values... that makes sense... my table is so simple, but sometimes I just like to play with the big stuff so I can learn it in case I need it later.

good to know, and good to see that line in the docs, I had been staring at the same page and somehow missing the info you clearly pointed out.

Now this weekend I get to learn about implementing foreign keys in mySQL... from the rumors I hear, that should be fun :) (I'm hoping they're all anti-mySQL zealots who don't know what they're talking about)

-Rob
 
Foreign keys aren't the panacea they're cracked up to be, especially if you control the interface to the data.

Their power really only comes to the fore when you have users able to run arbitrary queries.

If you control access to the data, then your program will not allow the user to enter "9 doors" in a car-describing field which should only take "4 door" or "2 door" (because the related table has only those 2 values).

If your users can run arbitrary queries, then the database server needs to be able to prevent that bad input. Want the best answers? Ask the best questions: TANSTAAFL!
 
You know, I put forth that same argument in the general database forum, and more than one individual basically called it a ridiculous notion.

Any the way, I don't imagine a scenario where I'll "need" them, but I'm still in my planning stages, and just trying to pick up plenty of knowledge before I start coding the big stuff.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top