Computer >> 컴퓨터 >  >> 프로그램 작성 >> MySQL

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)