[Mysql] SQL statements - add / modify Created Updated

SQL keywords should pay attention to the case

 

Table has been built, there is no creation time before the column,

Now create a new time, and set the default value for the current time

- Add CreateTime set the default time CURRENT_TIMESTAMP 

the ALTER  TABLE `table_name`
 the ADD  the COLUMN   ` CreateTime` datetime  NULL  the DEFAULT  CURRENT_TIMESTAMP the COMMENT ' Creation Time ' ;

 Table has been built, it has created time column

Created modify the default is the current time

- Modify the default settings CreateTime time CURRENT_TIMESTAMP 
the ALTER  TABLE `table_name` 
MODIFY the COLUMN   ` CreateTime` datetime  NULL  the DEFAULT  CURRENT_TIMESTAMP the COMMENT ' Creation Time ' ;

When the table has been built, a new update, the update time is set to update the data, the time stamp record 

- Add UpdateTime set the default time set CURRENT_TIMESTAMP CURRENT_TIMESTAMP the UPDATE update time to the ON 
the ALTER  TABLE `table_name`
 the ADD  the COLUMN ` UpdateTime` timestamp  NULL  the DEFAULT  CURRENT_TIMESTAMP  the ON  the UPDATE  CURRENT_TIMESTAMP the COMMENT 'update time ' ;

When the table has been built, the update time column already exists, set the update time to update the data, the time stamp record

- Modify UpdateTime set the default time set CURRENT_TIMESTAMP CURRENT_TIMESTAMP the UPDATE update time the ON 

the ALTER  TABLE `table_name` 
the MODIFY the COLUMN ` UpdateTime` timestamp  NULL  the DEFAULT  CURRENT_TIMESTAMP  the ON  the UPDATE  CURRENT_TIMESTAMP the COMMENT 'update time ' ;

 

Guess you like

Origin www.cnblogs.com/kaerxifa/p/11876549.html