Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:31+00:00 2026-05-16T10:11:31+00:00

This is a hard one (I think), on a SQL Server 2008 R2 database.

  • 0

This is a hard one (I think), on a SQL Server 2008 R2 database. I have a NotificationTemplate with zero to many NotificationSmsTemplate child bjects, because our SMS limits messages to 160 characters, I need to send several SMS’s in sequence to deliver the whole SMS communication. Per NotificationTemplate, each NotificationSmsTemplate has an SmsSequenceNumber property. This number can be anything as long as it is unique to it’s containing NotificationTemplate.

How can I ensure that the sequence numbers start 1 1 and are contiguous fro the collection of NotificationSmsTemplate objects for a containing NotificationTemplate. I can only think of using an internal sequence number to allow the user to order templates on teh screen, and then ordering by that, generate visible sequence numbers while inserting into the DB.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:11:32+00:00Added an answer on May 16, 2026 at 10:11 am

    If I understand your requirements correctly, you can take advantage of the way MySQL will reuse AUTO_INCREMENT values when the AUTO_INCREMENT column is part of a multiple-column index in a MyISAM table. See Using AUTO_INCREMENT for more details.

    Here’s an example to illustrate what I mean:

    Create a table to hold your notification templates:

    CREATE  TABLE IF NOT EXISTS `notification_template` (
      `id` INT NOT NULL AUTO_INCREMENT ,
      `notification` TEXT NOT NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = MyISAM;
    

    Create a table to hold the SMS templates:

    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;
    

    Insert a couple of long text passages into the notification_template table:

    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.');
    

    Insert the 160 character chunks into the notification_sms_template table, specifying the id of the notification_template to which they relate:

    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.');
    

    If you now select the the IDs from notification_sms_template, you will see that sms_sequence_number starts at 1 for each 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 |
    +--------------------------+---------------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a hard time on this one, I have a folder over
I have a hard time figuring this one out, it's about mistakes that can
In one of my process I have this SQL query that take 10-20% of
I am using SQL Server 2008 Enterprise. I have yearly customer data from 2000
I'm new to SQL and I don't think this question should be hard to
OK this is presumably a hard one, I've got an pyGTK application that has
I'm having a hard time figuring this one out. Seems like no matter what
I am having one heck of a hard time trying to figure this out.
I have something like this hard-coded: private string[,] m_RolesForUser = new string[,] { {John,President,Chair},
This question is hard to describe succinctly, so bear with me. Currently I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.