If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Generating unique id for users

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-08-10, 12:15
sunilmp sunilmp is offline
Registered User
 
Join Date: Jul 2010
Posts: 13
Generating unique id for users

Hi all,
I m designing a hospital management project, and I need to provide unique id to every patient. The requirement from our client is that the format of this unique id is: ddmmyyxxx. For example, 080710001, 080710002 etc
Here is what I did:
concat dd mm and yy strings. now concat auto increment field which is initialized with 000. so the first record will be ddmmyy000. and it will continue.

My problem is, after every day, the initial value of auto increment field(last three digits) shud be reset to 000. i.e., for 09/07/2010, the first record shud start with 090710000 and not some 090710xyz.
How this can be done? Shud I need to alter table every day to reset the auto increment value?




Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 07-08-10, 12:30
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
shud shud shud tsk tsk tsk

wtf are you gonna do, shud your hospital ever have more than 999 patients in a day?

someone in your company shud speak to your client about this nonsensical requirement
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-08-10, 12:51
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
Where is this hospital located (specifically what governmental oversite does the hospital need to meet)? They are almost certainly setting themselves up for a regulatory nightmare, and we need to understand which rules they need to comply with in order to advise you appropriately.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #4 (permalink)  
Old 07-08-10, 14:00
sunilmp sunilmp is offline
Registered User
 
Join Date: Jul 2010
Posts: 13
@r937
That requirement was posed for better readability of the ids.
There is one more constraint: assume we start with id 080710001. after some days, id will be ddmmyy999. The next id becomes ddmmyy1000. which doesnt fit under the specified format. Hence the better idea is to reset the last 3 digits every day.

Analogy: your room number 401 in a hotel doesnot imply that hotel has 400 more rooms.
Reply With Quote
  #5 (permalink)  
Old 07-08-10, 14:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by sunilmp View Post
That requirement was posed for better readability of the ids.
that's a very poor requirement in any case, and you did not meet it
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 07-08-10, 14:21
sunilmp sunilmp is offline
Registered User
 
Join Date: Jul 2010
Posts: 13
u can reply only if u have some basic knowledge about the topic.
Reply With Quote
  #7 (permalink)  
Old 07-08-10, 14:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
i guess that lets me out

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 07-08-10, 14:26
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
If you post such an obscure requirement you have to expect that people are going to question you about it.
Reply With Quote
  #9 (permalink)  
Old 07-08-10, 15:00
sunilmp sunilmp is offline
Registered User
 
Join Date: Jul 2010
Posts: 13
I'm not running away from answering to queries. But in the meantime, I want replies in favor of the topic and not some personal comments or disgusting remarks. If it is so obscure, then tell me your solution to this question. Will you answer in the same tone to your manager?
Reply With Quote
  #10 (permalink)  
Old 07-08-10, 19:12
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by sunilmp View Post
Will you answer in the same tone to your manager?
no, because he's paying me a ~lot~ more than you are

with you i can be honest

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Tags
alter_table, auto_increment

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On