Mega Code Archive

 
Categories / MySQL / Function
 

To see what the new seminar records look like, use the LAST_INSERT_ID() value to retrieve them

mysql> mysql> CREATE TABLE seminar(     ->     att_id     INT UNSIGNED NOT NULL,     ->     sem_title  ENUM('Database Design','Query Optimization','SQL Standards','Using Replication'),     ->     INDEX (att_id)     -> ); Query OK, 0 rows affected (0.00 sec) mysql> mysql> mysql> INSERT INTO seminar (att_id,sem_title) VALUES(LAST_INSERT_ID(),'Database Design'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO seminar (att_id,sem_title) VALUES(LAST_INSERT_ID(),'SQL Standards'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO seminar (att_id,sem_title) VALUES(LAST_INSERT_ID(),'Using Replication'); Query OK, 1 row affected (0.00 sec) mysql> mysql> mysql> SELECT * FROM seminar WHERE att_id = LAST_INSERT_ID(); +--------+-------------------+ | att_id | sem_title         | +--------+-------------------+ |      1 | Database Design   | |      1 | SQL Standards     | |      1 | Using Replication | +--------+-------------------+ 3 rows in set (0.00 sec) mysql> mysql> drop table seminar; Query OK, 0 rows affected (0.00 sec)