I have a mysql table called pollOfTheWeek. It has a column “pollDate” of type date. I have two questions regarding this :
1. I declared the column while creating the table as [pollDate date] What I wanted is that this column be set automatically, when the user doesnt enter any value for this column. How do i declare the column to achieve this?
- Assuming that I have the same declaration as above, how do I enter an empty value. I mean if the column was of type varchar, I would enter empty value as ” “. But since it is of type date, I get error when I enter the value as ” “. How do I enter empty value for the pollDate column?
MySQL has an extremely limited support for default values. In general, it must be a constant expression like
'0'or'(none)'and functions are not allowed. The only exception I’m aware of is that you can setCURRENT_TIMESTAMPas default value for aTIMESTAMPcolumn; however, this is not available forDATEorDATETIMEcolumns. Unluckily,TIMESTAMPhas a smaller range and contains time information.So your options are:
.
As about empty values, I would simply use NULL. Why use empty strings?