您可以使用 CURRENT_TIMESTAMP 设置系统日期时间。
让我们首先创建一个表 -
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientFirstName varchar(20), ClientLastName varchar(20), ClientAge int );
以下是在 MySQL 中将默认日期时间设置为系统日期时间的查询 -
mysql> alter table DemoTable add column ClientProjectDeadline timestamp default current_timestamp; Records: 0 Duplicates: 0 Warnings: 0
让我们再次检查表的描述 -
mysql> desc DemoTable;
这将产生以下输出 -
+-----------------------+-------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+-------------+------+-----+-------------------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | ClientFirstName | varchar(20) | YES | | NULL | | | ClientLastName | varchar(20) | YES | | NULL | | | ClientAge | int(11) | YES | | NULL | | | ClientProjectDeadline | timestamp | YES | | CURRENT_TIMESTAMP | | +-----------------------+-------------+------+-----+-------------------+----------------+ 5 rows in set (0.22 sec)