Page 1 of 1

General MySQL Questions

Posted: Fri Sep 21, 2007 3:56 pm
by icesolid
I was just wondering if these methods are the best to use:

#1. For boolean fields I used tinyint(1) (0 being false and 1 being true). I use that for true/false. Is that the best field type to use?

#2. When calling up a SELECT query, if I only need for ex: customer,amount,gross fields from the database, should I define them or is using * (select all) ok?

ex: is it better to do it this way:

Code: Select all

SELECT customer,amount,gross FROM cases
or this way:

Code: Select all

SELECT * FROM cases

Posted: Fri Sep 21, 2007 4:04 pm
by ReverendDexter
For #1, that's what I do, and I've yet to see anything better.

For #2, if I want specific data returned via a query, I ask for it, so I go with

Code: Select all

SELECT `column1`, `column2`
FROM `table`
This has the benefit of you knowing exactly what information is coming back and what's supposed to be in each column, and if you're querying remote databases, cuts down on superflous data transmission.

Now, if I'm sitting right at the server and doing some quick and dirty ad hoc querying, I'll do SELECT * just 'cause it's easier. But never in a script.

Posted: Fri Sep 21, 2007 4:17 pm
by pickle
I agree with the Rev.

FYI: MySQL kind of has a BOOLEAN type, so you can use that in your CREATE TABLE... queries. Of course, MySQL will convert it to tinyint(1) just like you did.

Posted: Fri Sep 21, 2007 10:15 pm
by icesolid
Does using ` ` around table and column names help or optimize the queries at all?

Posted: Sat Sep 22, 2007 12:01 am
by John Cartwright
It prevents possible name collisions of current and future reserved words