我们可以在MySQL中使用带有列时间戳默认值的表使用current_date()吗?
在MySQL中使用CURRENT_TIMESTAMP代替current_date()作为时间戳默认的current_date。让我们首先创建一个表。以下是查询-
mysql> create table defaultCurrent_DateDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentAdmissionDate timestamp default CURRENT_TIMESTAMP -> );
以下是使用insert命令在表中插入一些记录的查询-
mysql> insert into defaultCurrent_DateDemo(StudentName) values('Larry');
mysql> insert into defaultCurrent_DateDemo(StudentName,StudentAdmissionDate)
values('Chris','2019-01-31');以下是使用select语句显示表中所有记录的查询-
mysql> select *from defaultCurrent_DateDemo;
这将产生以下输出-
+-----------+-------------+----------------------+ | StudentId | StudentName | StudentAdmissionDate | +-----------+-------------+----------------------+ | 1 | Larry | 2019-04-02 19:38:19 | | 2 | Chris | 2019-01-31 00:00:00 | +-----------+-------------+----------------------+ 2 rows in set (0.00 sec)
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短