MySQL Forums
Forum List  »  Newbie

Re: Can't create NOT NULL timestamp
Posted by: Bob Woodward
Date: September 03, 2015 04:53PM

If I'm not mistaken, a TIMESTAMP attribute is automatically NOT NULL and you have use the NULL keyword to override that. At least if it's the first TIMESTAMP attribute in the file. As you can see below, the "Null" column (sorry for the formatting) is NO for both attributes and the "Default" is CURRENT_TIMESTAMP on the startTime attribute. This should do what you're looking for.

mysql> CREATE TABLE sample1 (
-> id int(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
-> startTime TIMESTAMP
-> );
Query OK, 0 rows affected (0.08 sec)

mysql> show columns from sample1;
+-----------+
| Field | Type | Null | Key | Default | Extra
+-----------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment
| startTime | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP
+-----------+
2 rows in set (0.01 sec)

mysql>

Options: ReplyQuote


Subject
Written By
Posted
September 02, 2015 10:53AM
Re: Can't create NOT NULL timestamp
September 03, 2015 04:53PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.