我可以输入 MySql table 插入数据的确切时间吗?
Can I put in a MySql table the exact time of when inserted a data?
我正在构建一个数据库,我需要知道我在 table 中插入一些数据时的 hh:mm:ss,以使其作为自身的一列结果 table.
如果我解释得很好,我会举个例子:
我需要这样的 table:
------------------------------------------
| IDtable | users | passwords | log_time |
| ---------------------------------------|
| 1 | dude | dudepass | hh:mm:ss |
------------------------------------------
在 MySQL 中,您可以存储使用 auto-initialized 列创建记录时的时间戳。
create table mytable (
id int primary key auto_increment,
username varchar(50),
password varchar(50),
created_ts timestamp default current_timestamp
);
然后你 insert
进入 table 像这样:
insert into mytable(username, password) values('foo', 'bar');
并且 created_ts
自动初始化为插入时的当前 date/time。
您还可以使用 on update
子句跟踪最后一次 更改 行的时间点:
create table mytable (
id int primary key auto_increment,
username varchar(50),
password varchar(50),
created_ts timestamp default current_timestamp,
updated_ts timestamp default current_timestamp on update current_timestamp
);
我正在构建一个数据库,我需要知道我在 table 中插入一些数据时的 hh:mm:ss,以使其作为自身的一列结果 table.
如果我解释得很好,我会举个例子:
我需要这样的 table:
------------------------------------------
| IDtable | users | passwords | log_time |
| ---------------------------------------|
| 1 | dude | dudepass | hh:mm:ss |
------------------------------------------
在 MySQL 中,您可以存储使用 auto-initialized 列创建记录时的时间戳。
create table mytable (
id int primary key auto_increment,
username varchar(50),
password varchar(50),
created_ts timestamp default current_timestamp
);
然后你 insert
进入 table 像这样:
insert into mytable(username, password) values('foo', 'bar');
并且 created_ts
自动初始化为插入时的当前 date/time。
您还可以使用 on update
子句跟踪最后一次 更改 行的时间点:
create table mytable (
id int primary key auto_increment,
username varchar(50),
password varchar(50),
created_ts timestamp default current_timestamp,
updated_ts timestamp default current_timestamp on update current_timestamp
);