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

  • SEARCH
  • Home
  • 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 8481999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:42:42+00:00 2026-06-10T19:42:42+00:00

I have a problem trying to get my head around a database problem. The

  • 0

I have a problem trying to get my head around a database problem. The situation is as follows for a school enroling system.

Table 1 : School
CREATE TABLE school (schoolID auto_increment, school_name varchar, etc etc)

Table 2 : Students
CREATE TABLE students (studentID auto_increment, student_name varchar, etc etc)

Table 3 : Enrolments (problem is here I believe)
CREATE TABLE enrolments (enrolID, …)

The issue is, previously the scope for the system was to allow enrolments to come from any number of locations, at any time, and would just insert into the database, which was fine, everything was autoincremented.

The scope changed, as they did not like the fact, that when reports would be done, when they retrieved the enrolments the numbers for the enrolments were scattered. They wanted each schools enrolment ID’s to be sequential.

One thought I had was, option (a)

Create an enrolment table for every school (looking at around 1000-1500 total schools), this way every enrolment inserted, would be stored sequentially.

Option (B)

Have another table that would record the “lastrecord” inserted for that school.

CREATE TABLE lastrecord (schoolname varchar, nextrecord int)

With this, before every insert, it would have to check the database to find what the last ID used for that school was, retrieve the value, +1 to it, and then INSERT into the enrolment table.

using this method I would prefix the enrolment ID with the schools ID, for example
schoolID : 100

new enrolment ID : 10045
for their 45th student.

Then after every insert, update that table with the record used. This seems extremely inefficient but I am struggling to work out a better solution.

thank you in advance for any help.

  • 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-06-10T19:42:43+00:00Added an answer on June 10, 2026 at 7:42 pm

    You could make the autoincrement on two fields

    Like:
    ADD PRIMARY KEY (school_id,enrolID)
    and set enrolID to autoincrement

    Then each school will have its own autoincrement

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my head around solving the following problem. I have the
Strange problem I can't seem to get my head around. I have a table
I have a problem trying to get my head around using UTF8 with Poco::XML::XMLWriter
I'm trying to get my head around this one: Say you have two models
I have been trying to get my head around to make things work with
I'm trying to get my head around TDD methodology and have run into -
Hey all, i have a problem with trying to get 2 forms to close
I'm trying to get a handle on whether we have a problem in our
I have a problem with this query trying to get a sum and a
I have a problem with a page where I am trying to get colorbox

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.