How to get the creation time of recently created table in MySQL?

MySQLMySQLi Database

Following is the syntax −

select table_name, create_time
from information_schema.TABLES
where table_schema = 'yourDataBaseName'
order by CREATE_TIME desc
limit 1;

Let us create the first table (Time: 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)

We will now create the second table, let’s say after 5 minutes −

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)

Now we will get the time of the latest created table in MySQL (i.e. DemoTable2 as it is the recently created table) −

mysql> select table_name, create_time
   -> from information_schema.TABLES
   -> where table_schema = 'web'
   -> order by CREATE_TIME desc
   -> limit 1;

Output

+--------------+---------------------+
| TABLE_NAME   | CREATE_TIME         |
+--------------+---------------------+
| demotable2   | 2019-06-10 16:45:51 |
+--------------+---------------------+
1 row in set (0.01 sec)
raja
Published on 09-Jul-2019 16:15:31
Advertisements