Using LAST_INSERT_ID() in insert statement
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> drop table seminar;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category