如何獲取 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)

更新於: 30-Jul-2019

161 次瀏覽

開啟您的 職業生涯

完成本課程將獲得認證

開始
廣告
© . All rights reserved.