Table with TIMESTAMP data type : TIMESTAMP « Date Time « SQL / MySQL






Table with TIMESTAMP data type

     
mysql>
mysql> CREATE TABLE IF NOT EXISTS user_log
    -> (
    ->   id INT,
    ->   date TIMESTAMP,
    ->   first_name VARCHAR(20),
    ->   last_name  VARCHAR(20)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> # confirm the "user_log" table format
mysql> EXPLAIN user_log;
+------------+-------------+------+-----+-------------------+-----------------------------+
| Field      | Type        | Null | Key | Default           | Extra                       |
+------------+-------------+------+-----+-------------------+-----------------------------+
| id         | int(11)     | YES  |     | NULL              |                             |
| date       | timestamp   | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| first_name | varchar(20) | YES  |     | NULL              |                             |
| last_name  | varchar(20) | YES  |     | NULL              |                             |
+------------+-------------+------+-----+-------------------+-----------------------------+
4 rows in set (0.00 sec)

mysql>
mysql> # delete this sample table
mysql> DROP TABLE user_log;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
  








Related examples in the same category

1.The TIMESTAMP column type
2.Displaying TIMESTAMP Values in Readable Form
3.If you modify multiple records, the TIMESTAMP values in all of them will be updated:
4.Add Microsecond to time
5.Records created from 1 PM to 4 PM:
6.Records modified within the last 12 hours: