SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: More PHP / MySQL Help...
-
Dec 16, 2000, 01:24 #1
- Join Date
- Sep 2000
- Location
- Milwaukee, WI
- Posts
- 225
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Two questions:
1) What's the difference between CHAR and VARCHAR ?? After reading the docs on mysql.com page I don't see a difference.
2) I am pulling rows of data from a table in MySQL. One column in the row is a TINYINT. How do I go about sorting to display the row with the largest TINYINT first, and so on down to the lowest one?
Thanks.
-
Dec 16, 2000, 02:08 #2
- Join Date
- Aug 2000
- Location
- Silicon Valley
- Posts
- 2,241
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here we go
1. CHAR(length) will be fix, even if you put one single character in it, it still takes "length" while in the same situation, VARCHAR(length) should take only one --> you save some space! I've heard that there is tradeoff between space and performance. CHAR (faster) vs. VARCHAR (slower)
If you aren't making huge DB or need to fetch many data, VARCHAR is my choice!
2. Use this query:
"SELECT whatever FROM table ORDER BY littleIntCol DESC"- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy
-
Dec 16, 2000, 02:39 #3
- Join Date
- Sep 2000
- Location
- Milwaukee, WI
- Posts
- 225
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks
-
Dec 16, 2000, 03:15 #4
- Join Date
- Jul 2000
- Location
- Perth Australia
- Posts
- 1,717
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
MySQL will alter the TYPE for varchar & char to use the most effecient one, ie if you use type char and MySQL thinks that varchar is better... it will change the type so I would not worry too much about it!
-
Dec 16, 2000, 11:09 #5
- Join Date
- Aug 2000
- Location
- Silicon Valley
- Posts
- 2,241
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
firepages,
What do you mean by MySQL "think" and decide which one is better?
It must have some rule for it to do that, and what are they?
Or you could just redirect me to a page discussing about that. Thanks- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy
-
Dec 17, 2000, 00:53 #6
- Join Date
- Jul 2000
- Location
- Perth Australia
- Posts
- 1,717
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is section 7.7.1 from the MySQL I have 3.22 I think...
"
7.7.1 Silent column specification changes
In some cases, MySQL silently changes a column specification from that given in a CREATE TABLE statement. (This may also occur with ALTER TABLE.)
VARCHAR columns with a length less than four are changed to CHAR.
If any column in a table has a variable length, the entire row is variable-length as a result. Therefore, if a table contains any variable-length columns (VARCHAR, TEXT or BLOB), all CHAR columns longer than three characters are changed to VARCHAR columnss. This doesn't affect how you use the columns in any way; in MySQL, VARCHAR is just a different way to store characters. MySQL performs this conversion because it saves space and makes table operations faster. See section 10.6 Choosing a table type.
TIMESTAMP display sizes must be even and in the range from 2 to 14. If you specify a display size of 0 or greater than 14, the size is coerced to 14. Odd-valued sizes in the range from 1 to 13 are coerced to the next higher even number.
You cannot store a literal NULL in a TIMESTAMP column; setting it to NULL sets it to the current date and time. Because TIMESTAMP columns behave this way, the NULL and NOT NULL attributes do not apply in the normal way and are ignored if you specify them. DESCRIBE tbl_name always reports that a TIMESTAMP column may be assigned NULL values.
MySQL maps certain column types used by other SQL database vendors to MySQL types. See section 7.3.11 Using column types from other database engines.
If you want to see whether or not MySQL used a column type other than the one you specified, issue a DESCRIBE tbl_name statement after creating or altering your table. "
Athough this is mentioned in the TYPE descriptions in other parts of the manual as well.
-
Dec 17, 2000, 11:17 #7
- Join Date
- Aug 2000
- Location
- Silicon Valley
- Posts
- 2,241
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oh yeah, I saw the title of this section once but didn't read it.
Secondly, just tried to change from VARCHAR(15) to VAR(15) and it still VARCHAR(15)
Thanks a lot firepages!- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy
Bookmarks