如何获取 MySQL 中最近创建的表中的创建时间?
以下是语法 −
select table_name, create_time from information_schema.TABLES where table_schema = 'yourDataBaseName' order by CREATE_TIME desc limit 1;
让我们创建第一个表(时间:2019-06-10 16:40:51) −
mysql> create table DemoTable1 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (0.59 sec)
我们现在将创建第二个表,假定在 5 分钟后 −
mysql> create table DemoTable2 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (0.59 sec)
现在,我们将在 MySQL 中获取最新创建表的的时间(即 DemoTable2,因为它是最新的表) −
mysql> select table_name, create_time -> from information_schema.TABLES -> where table_schema = 'web' -> order by CREATE_TIME desc -> limit 1;
输出
+--------------+---------------------+ | TABLE_NAME | CREATE_TIME | +--------------+---------------------+ | demotable2 | 2019-06-10 16:45:51 | +--------------+---------------------+ 1 row in set (0.01 sec)
广告