I want to generate stu_id as uatonumber: S001, S002, I don't have any concept to do this. Please help me or give me direct link to learn this method. Thank you
Generate autonumber manually in MySQL
Moderator: General Moderators
Generate autonumber manually in MySQL
I want to generate stu_id as uatonumber: S001, S002, I don't have any concept to do this. Please help me or give me direct link to learn this method. Thank you
Re: Generate autonumber manually in MySQL
You can't manually generate an autonumber. Autonumber is "automatic" meaning no intervention required. Manual mean you decide what the number is.
But, if you want to find out what the most recent user_id created is, query max(user_id) and add one to it. Use a regular expression to strip off the s and leading zeros.
But really, is there any reason you have to store s001, s002, etc? why not just use autonumber and then prepend it with an s as needed. Unless the number is assigned somewhere else and you're storing it, in which case it's user input.
But, if you want to find out what the most recent user_id created is, query max(user_id) and add one to it. Use a regular expression to strip off the s and leading zeros.
But really, is there any reason you have to store s001, s002, etc? why not just use autonumber and then prepend it with an s as needed. Unless the number is assigned somewhere else and you're storing it, in which case it's user input.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Generate autonumber manually in MySQL
Look into emulating sequences in MySQL. The code is fairly simple to implement.
(#10850)