Если я правильно понимаю ваши требования, вы можете воспользоваться тем, как MySQL будет повторно использовать значения AUTO_INCREMENT, когда столбец AUTO_INCREMENT является частью индекса из нескольких столбцов в таблице MyISAM.См. Использование AUTO_INCREMENT для получения более подробной информации.
Вот пример, чтобы проиллюстрировать, что я имею в виду:
Создайте таблицу для хранения ваших шаблонов уведомлений:
CREATE TABLE IF NOT EXISTS `notification_template` (
`id` INT NOT NULL AUTO_INCREMENT ,
`notification` TEXT NOT NULL ,
PRIMARY KEY (`id`) )
ENGINE = MyISAM;
Создайте таблицу для хранения шаблонов SMS:
CREATE TABLE IF NOT EXISTS `notification_sms_template` (
`notification_template_id` INT NOT NULL ,
`sms_sequence_number` INT NOT NULL AUTO_INCREMENT ,
`sms` VARCHAR(160) NOT NULL ,
PRIMARY KEY (`notification_template_id`, `sms_sequence_number`) )
ENGINE = MyISAM;
Вставьте пару длинных текстовых отрывков в таблицу notification_template
:
INSERT INTO `notification_template` (`id`, `notification`) VALUES
(1, 'Tell me, O Muse, of that ingenious hero who travelled far and wide after he had sacked the famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs he was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely home; but do what he might he could not save his men, for they perished through their own sheer folly in eating the cattle of the Sun-god Hyperion; so the god prevented them from ever reaching home. Tell me, too, about all these things, oh daughter of Jove, from whatsoever source you may know them.'),
(2, 'There were once a man and a woman who had long in vain wished for a child. At length the woman hoped that God was about to grant her desire. These people had a little window at the back of their house from which a splendid garden could be seen, which was full of the most beautiful flowers and herbs. It was, however, surrounded by a high wall, and no one dared to go into it because it belonged to an enchantress, who had great power and was dreaded by all the world.');
Вставьте куски по 160 символов вnotification_sms_template
таблица с указанием id
из notification_template
, к которому они относятся:
INSERT INTO `notification_sms_template` (`notification_template_id`, `sms`) VALUES
(1, 'Tell me, O Muse, of that ingenious hero who travelled far and wide after he had sacked the famous town of Troy. Many cities did he visit, and many were the nat'),
(1, 'ions with whose manners and customs he was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely home; but do'),
(1, ' what he might he could not save his men, for they perished through their own sheer folly in eating the cattle of the Sun-god Hyperion; so the god prevented th'),
(1, 'em from ever reaching home. Tell me, too, about all these things, oh daughter of Jove, from whatsoever source you may know them.'),
(2, 'There were once a man and a woman who had long in vain wished for a child. At length the woman hoped that God was about to grant her desire. These people had a'),
(2, ' little window at the back of their house from which a splendid garden could be seen, which was full of the most beautiful flowers and herbs. It was, however, '),
(2, 'surrounded by a high wall, and no one dared to go into it because it belonged to an enchantress, who had great power and was dreaded by all the world.');
Если вы сейчас выберете идентификаторы из notification_sms_template
, вы увидите, что sms_sequence_number
начинается с1 за каждый notification_template
:
SELECT `notification_template_id`, `sms_sequence_number`
FROM `notification_sms_template`;
+--------------------------+---------------------+
| notification_template_id | sms_sequence_number |
+--------------------------+---------------------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
+--------------------------+---------------------+