NOW関数は、現在の日付と時刻を返す関数です。
NOW
記述
NOW()
【日時確認】
mysql> SELECR NOW();
+---------------------+
| NOW() |
+---------------------+
| 2024-04-02 00:01:00 |
+---------------------+
1 row in set (0.00 sec)
【informationsテーブル一覧表示】
mysql> SELECT * FROM informations;
+----+------------+---------------------+---------------------+
| id | name | created_at | updated_at |
+----+------------+---------------------+---------------------+
| 1 | test info1 | 2024-04-01 00:01:00 | 2024-04-01 00:01:00 |
+----+------------+---------------------+---------------------+
1 rows in set (0.00 sec)
【追加】
mysql> INSERT INTO informations VALUES (2, "test info2", NOW(), NOW());
【informationsテーブル一覧表示】
mysql> SELECT * FROM informations;
+----+------------+---------------------+---------------------+
| id | name | created_at | updated_at |
+----+------------+---------------------+---------------------+
| 1 | test info1 | 2024-04-01 00:01:00 | 2024-04-01 00:01:00 |
| 2 | test info2 | 2024-04-02 00:01:23 | 2024-04-02 00:01:23 |
+----+------------+---------------------+---------------------+
1 rows in set (0.00 sec)