List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 25 2002 8:02pm
Subject:Re: Auto_increment and TimeStamp Fields
View as plain text  
At 14:54 -0500 3/25/02, Eric Baines wrote:
>I have created a table with a Primary Key that is an auto_incrementing
>field.  I was able to receive the auto_increment values by issuing a
>last_insert_id().  When I added a timestamp to this table, the
>last_insert_id() no longer returned any value except 0.
>
>Is there a MySQL rule that you can not have an auto_increment field and a
>timestamp field in the same table?

No, you can have both.

mysql> CREATE TABLE t
     -> (i INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
     -> ts TIMESTAMP);
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t SET ts = NULL;
Query OK, 1 row affected (0.01 sec)

mysql> SELECT LAST_INSERT_ID();
+------------------+
| last_insert_id() |
+------------------+
|                1 |
+------------------+
1 row in set (0.01 sec)

mysql> INSERT INTO t SET ts = NULL;
Query OK, 1 row affected (0.00 sec)

mysql> SELECT LAST_INSERT_ID();
+------------------+
| last_insert_id() |
+------------------+
|                2 |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM t;
+---+----------------+
| i | ts             |
+---+----------------+
| 1 | 20020325140102 |
| 2 | 20020325140102 |
+---+----------------+
2 rows in set (0.00 sec)


Thread
Auto_increment and TimeStamp FieldsEric Baines25 Mar
  • Re: Auto_increment and TimeStamp FieldsPaul DuBois25 Mar
Re: Auto_increment and TimeStamp FieldsEric Baines25 Mar