Inserting name values into the multisequence table generates separate sequences for each distinct name:
mysql>
mysql> CREATE TABLE multisequence
-> (
-> name CHAR(10) NOT NULL,
-> name_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
-> PRIMARY KEY (name, name_id)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> INSERT INTO multisequence (name) VALUES('Petr'),('Ilya'),('Ilya'),('Yuri'),('Ilya'),('Petr');
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql>
mysql> SELECT * FROM multisequence ORDER BY name, name_id;
+------+---------+
| name | name_id |
+------+---------+
| Ilya | 1 |
| Ilya | 2 |
| Ilya | 3 |
| Petr | 1 |
| Petr | 2 |
| Yuri | 1 |
+------+---------+
6 rows in set (0.00 sec)
mysql>
mysql> drop table multisequence;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category