时间与时间MySQL表行中的日期戳
我想花点时间&每行的日期戳添加到MySQL表中.如果我理解正确,则需要为时间&日期戳.对于下面的CREATE TABLE查询,我该怎么做?
I would like to put a time & date stamp on each row added to a MySQL table. If I understand correctly, I need to create a column for the time & date stamp. How do I do that for the CREATE TABLE query below?
"CREATE TABLE `$table` (id INT(11) NOT NULL auto_increment, site VARCHAR(1000) NOT NULL, actions1 BIGINT(9) NOT NULL, actions2 BIGINT(9) NOT NULL, PRIMARY KEY(id), UNIQUE (site))"
此外,如果我理解正确,那么每次在表中插入一行时,都需要添加该标记.对于下面的INSERT INTO查询,我该怎么做?
Also, if I understand correctly, I would then need to add the stamp each time a row is inserted to the table. How would I do that for the INSERT INTO query below?
"INSERT INTO `$find` VALUES (NULL, '$site',1,0)"
预先感谢
约翰
您需要添加TIMESTAMP列,如下所示:
You need to add a TIMESTAMP column like this:
CREATE TABLE `$table` (
id INT(11) NOT NULL auto_increment,
site VARCHAR(1000) NOT NULL,
actions1 BIGINT(9) NOT NULL,
actions2 BIGINT(9) NOT NULL,
CreatedDateTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
PRIMARY KEY(id), UNIQUE (site))
这将创建一列CreatedDateTime,其中包含创建行的(服务器)时间.
That will make a column CreatedDateTime which contains the (server) time the row was created.
您可以通过以下方式进行插入:
You can do the insert as:
INSERT INTO `$find` (site, actions1, actions2) VALUES ('$site', 1, 0)
有关更多参考,请参见此处
For further reference see here