Home >Database >Mysql Tutorial >How to get the creation date of a MySQL table?

How to get the creation date of a MySQL table?

王林
王林forward
2023-08-27 13:33:181192browse

如何获取 MySQL 表的创建日期?

To get the creation date of a MySQL table, use information_schema. The syntax is as follows -

SELECT create_time FROM INFORMATION_SCHEMA.TABLES
   WHERE table_schema = 'yourDatabaseName’
   AND table_name = 'yourTableName';

Apply the above syntax to your database and table names. Here I use the database "business" and the table name is "student". The query is as follows -

mysql> SELECT create_time FROM INFORMATION_SCHEMA.TABLES
   -> WHERE table_schema = 'business'
   -> AND table_name = 'student';

The following is the output showing the table creation time -

+---------------------+
| CREATE_TIME         |
+---------------------+
| 2018-10-01 12:26:57 |
+---------------------+
1 row in set (0.12 sec)

Let us see another example and create a table from scratch.

mysql> create table DateAsStringDemo
   -> (
   -> YourDateTime datetime
   -> );
Query OK, 0 rows affected (0.57 sec)

I have just created a table and my current date time is as follows -

mysql> select now();

Below is the output -

+---------------------+
| now()               |
+---------------------+
| 2018-11-26 18:12:29 |
+---------------------+
1 row in set (0.00 sec)

Now you can check the creation time of the above table, it The date 2018-11-26 will be given.

The query is as follows -

mysql> SELECT create_time FROM INFORMATION_SCHEMA.TABLES
   -> WHERE table_schema = 'test'
   -> AND table_name = 'DateAsStringDemo';

The following is the output -

+---------------------+
| CREATE_TIME         |
+---------------------+
| 2018-11-26 18:01:44 |
+---------------------+
1 row in set (0.00 sec)

The above is the detailed content of How to get the creation date of a MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete