Each time a conference registration form is received, enter the attendee information into the attendee table. : LAST_INSERT_ID « Function « SQL / MySQL






Each time a conference registration form is received, enter the attendee information into the attendee table.

       
For example:
mysql>
mysql> CREATE TABLE attendee(
    ->     att_id      INT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->     att_name    CHAR(100),
    ->     att_title   CHAR(40),
    ->     PRIMARY KEY (att_id)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO attendee (att_name,att_title) VALUES('Charles Loviness','IT Manager');
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> SELECT * FROM attendee WHERE att_id = LAST_INSERT_ID();
+--------+------------------+------------+
| att_id | att_name         | att_title  |
+--------+------------------+------------+
|      1 | Charles Loviness | IT Manager |
+--------+------------------+------------+
1 row in set (0.00 sec)

mysql>
mysql> drop table attendee;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
    
  








Related examples in the same category

1.Save the result from LAST_INSERT_ID( ) after creating a new record in a table that has an AUTO_INCREMENT column to a variable
2.Update with LAST_INSERT_ID
3.Using LAST_INSERT_ID() in insert statement
4.To see what the new seminar records look like, use the LAST_INSERT_ID() value to retrieve them:
5.Use the new value to retrieve the entire record, without even knowing what the id is