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)



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to