Mysql> create a table by adding this column and stating default values as follows:
CREATE TABLE `table1` ( `id` int(11) NOT NULL, `createtime` timestamp NULL default CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
If you are operating under Navicat, set the field type to TIMESTAMP, and write CURRENT_TIMESTAMP as the default value, as shown below:
Add a new column to an existing table
ALTER TABLE table1 ADD COLUMN `createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP
3. Modify the time format of a column and add the default value
alter table table1 change createtime newtime timestamp null default current_timestamp
Read More:
- In SQLite database, set the default value for the field as the current time
- MySQL:ERROR 1067 (42000): Invalid default value for ‘end_time’
- How to get the current time in java time string
- MySQL will delete the data minutes before the current time
- PostgreSQL sets the default value of the field to the current year
- Linux view current date and time
- Shell gets the current time of the system and formats it
- The shell gets the current time of the system and formats it
- An error was reported in the process of importing the table from mysql5.7: [err] 1067 – invalid default value for ‘***‘
- MySQL error set: failed to start mysql.service : Unit mysql.service is masked.
- Run with Python console solution is set by default for all projects in pcharm
- Error (1820) if the password is not changed in time after MySQL installation
- Common shell (1): shell gets the current time stamp of the system
- Error attempting to get column time from result set. Cause: java.sql.SQLFe
- [antdv: DatePicker] `value` provides invalidate moment time. If you want set empty value, use `null`
- MySQL modify character set
- mysql workbench Error Code: 1046. No database selected Select the default DB to be used
- MYSQL:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
- [reprint and save] MySQL does not set the primary key and uses the self growing ID method
- Top35: pychar reports an error when connecting to MySQL server returns invalid timezone. Need to set ‘servertimezone’ property