1. Set the default character value for the field
ALTER TABLE ' v_users '
MODIFY COLUMN ' picture ' varchar (a) CHARACTER SET UTF8 COLLATE utf8_general_ci NULL DEFAULT ' 3.jpg ' after ' phone ';
Note that when you set the default value for the Picture field to 3.jpg, you add a single quotation mark, which is also required when working in Navicat, or 1064 error is reported.
2. Set the default time for the field to the current time
Because the default value for the current field in MySQL does not support functions, it is not possible to set the default value in the form of create_time datetime default Now (). The alternative is to use the timestamp type instead of the datetime type. The timestamp column type automatically marks the INSERT or update operation with the current date and time. If there are multiple timestamp columns, only the first one is automatically updated.
The automatic update of the first timestamp column occurs under any of the following conditions:
- Column values are not explicitly specified in an INSERT or load DATA infile statement.
- Column values are not explicitly specified in an UPDATE statement and some other columns change values. (Note An update setting that lists the values it already has, which will not cause the timestamp column to be updated, because if you set a list as its current value, MySQL ignores the changes for efficiency.) )
- You explicitly set the timestamp column to be null.
- The timestamp column other than the first one can also be set to the current date and time, as long as the column is set to NULL, or now ().
So choose the date type to timestamp allow empty.
CREATE TABLE Test ( uname varchar () NOT NULL, updatetime timestamp null defaultcurrent_timestamp on UPDATE Curre Nt_timestamp) Engine=innodb DEFAULT Charset=utf8;
If you want to operate under Navicat, set the field to timestamp, and then write the default value Current_timestamp.
MySQL and Navicat usage summary