如何知道在SQL中插入记录的日期 [英] how to know the date of insertion of record in SQL

查看:537
本文介绍了如何知道在SQL中插入记录的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为项目使用phpMyAdmin,并且我有一个没有date/datetime字段的表.

I am using phpMyAdmin for my project and I have a table without date/datetime field.

我想知道是否有一种方法可以知道何时将每条记录插入数据库中

I am wondering if there's a way to know when I inserted each record on the database

推荐答案

在设计数据库时,如果您忘记保留额外的字段来存储行的插入时间,那么您只剩下一个选项来知道插入时间

While designing your database if you forgot to keep an extra field to store the insertion time of a row then you have only one option left to know the the insertion time.

但是条件是您必须先启用二进制日志记录.

参考

您可以通过执行以下查询来检查您的部分是否启用了二进制日志记录:

You may check if binary logging is enabled in your part by executing this query :

SHOW VARIABLES LIKE 'log_bin';

更多说明:

从现在开始,您可以保留一个额外的字段,该字段将跟踪每行的插入时间.

And from now on you may keep an extra field which will track the insertion time of each row.

更改表格设计:

在表中添加一个额外字段,其数据类型为时间戳/日期时间",默认值为CURRENT_TIMESTAMP,并在更新时为CURRENT_TIMESTAMP.

Add an extra field in your table with datatype "timestamp/datetime" with default value CURRENT_TIMESTAMP and on update CURRENT_TIMESTAMP.

这篇关于如何知道在SQL中插入记录的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆