Results 1 to 3 of 3
Aug 1, 2012, 19:03 #1
When do I use NULL as Default value for SET, CHAR, VARCHAR data types?
I have two questions. One is about the SET data type. The other is about the CHAR and VARCHAR data types.
Question 1 regarding SET
I am trying to figure out when it is proper to use NULL as one of the values.
For example, if I need no value do I use an empty value like this:
set('', 'Yes', 'No')
or would it be best to set it to NULL like this:
set('NULL', 'Yes', 'No')
On this page in the MySQL manual it uses NOT NULL for the SET value at the top of the page. However, about 1/8 way down the page it says that SET values are sorted numerically and that NULL values sort before non-NULL SET values.
Question 2 regarding CHAR, VARCHAR
Same as question above. If I need just an empty value in a table cell do I use NULL in the database table or do I just use a blank table cell.
For the INT data types: I am having to use NULL for the int types because if I use an empty value PHP will display a "0" in the browser instead of no value.
I would appreciate any information.
Aug 1, 2012, 22:14 #2
- Join Date
- Jul 2002
- Toronto, Canada
- 52 Post(s)
- 2 Thread(s)
NULL is not a value
by the way, SET is one of those proprietary mysql datatypes (ENUM is another) which i urge people not to use because of portability issues
SET is damned convenient, though, and not using it is typically more difficult, as it usually involves two additional tables
NULL is for when you want the column value to be undefined, unknown, not appropriate, or missing
Aug 3, 2012, 04:32 #3
Thanks for responding to my question. I appreciate the information..