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:
- MySQL:ERROR 1067 (42000): Invalid default value for ‘end_time’
- MySql ERROR CODE:1215 Cannot add the foreign key constraint
- Modification method of starting value of MySQL auto increment ID
- Perfectly solve the 1366 error of saving Chinese in MySQL
- 1822 – Failed to add the foreign key constraint. Missing index for constraint ‘tb_emp_ibfk_1’ in the
- Solutions to UCenter Info: MySQL query error app1
- Wamp install WordPress prompt can’t select database
- MySQL partitions the existing tables of the data table
- Solution of MySQL data garbled problem
- Common shell (1): shell gets the current time stamp of the system
- PHP – PHP Error[2]: Error while sending QUERY packet. PID=*
- mysql ERROR 1050 (42S01): Table already exists
- Local date time conversion in java8
- 13. R language: Error in match.names(clabs, names(xi)): The name is not relative to the original name
- MySQL error 1451 23000 foreign key exception handling
- MySQL password setting error message: error 1054 (42s22): unknown column ‘password’ in ‘field list’
- MySQL ERROR 1054 (42S22): Unknown column’password’ in’field list’ error
- Fatal error: Please read “Security” section of the manual to find out how to run mysqld as root!
- In depth analysis of mysq exceeding the number of connections error 1040 (HY000): too many connections
- How to Fix SQL Error: 1054, SQLState: 42S22 Unknown column ‘markcardex0_.art_service_time’ in ‘field list’