Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MySQL

Xem ngày tạo và cập nhật bảng trong MySQL

Dùng lệnh SHOW TABLE STATUS để xem thông tin chi tiết các bảng, bao gồm Create_time và Update_time.

Chọn database:

mysql> USE test3;

Liệt kê bảng:

mysql> SHOW TABLES;

Xem trạng thái bảng:

mysql> SHOW TABLE STATUS;

Kết quả (các cột quan trọng):

+-------------------------+---------------------+-------------+
| Name                    | Create_time         | Update_time |
+-------------------------+---------------------+-------------+
| add6hour                | 2019-02-14 18:33:27 | NULL        |
| deletedemo              | 2019-02-13 19:20:04 | NULL        |
| differentdatetime       | 2019-02-14 10:26:28 | NULL        |
| fieldlessthan5chars     | 2019-02-13 19:03:05 | NULL        |
| lastrecordbeforelastone | 2019-02-14 17:31:59 | NULL        |
| mostrecentdatedemo      | 2019-02-14 17:15:53 | NULL        |
| nullcasedemo            | 2019-02-14 17:55:39 | NULL        |
| order                   | 2019-02-14 14:23:38 | NULL        |
| orderbydatethentimedemo | 2019-02-14 18:05:36 | NULL        |
| posts                   | 2019-02-13 18:19:06 | NULL        |
| productdemo             | 2019-02-13 20:06:36 | NULL        |
| radiansdemo             | 2019-02-14 14:33:24 | NULL        |
| siglequotesdemo         | 2019-02-14 10:41:23 | NULL        |
| studentinformation      | 2019-02-14 17:06:07 | NULL        |
| updatestringdemo        | 2019-02-13 18:25:59 | NULL        |
+-------------------------+---------------------+-------------+

Lưu ý: Update_time thường là NULL cho engine InnoDB do cách lưu trữ. Để theo dõi thay đổi, cân nhắc dùng trigger hoặc cột TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.