473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

prefix word to autoincrement

pradeepjain
563 512MB
Hi,
I have a mysql table where in i have a field called patient_id which i do an auto increment and its the primary key !! since this number goes on patient card also simply 1,2 will not be gud . Is there a way to prefix some text to it like patient1, patient2 something like that!!!
Sep 10 '09 #1
6 14510
Dormilich
8,658 Expert Mod 8TB
if it were possible to read the auto increment value in the insert process, you could use a function. you should ask the people in the MySQL forum if that’s possible.
Sep 10 '09 #2
Atli
5,058 Expert 4TB
Sure:
Expand|Select|Wrap|Line Numbers
  1. SELECT CONCAT('patient', `patient_id`) FROM `patient_table`
Sep 10 '09 #3
pradeepjain
563 512MB
@Atli
You got ma question wrong ! while auto_incrementing can we prefix some text to the autoincremented value!!!?
Sep 10 '09 #4
Atli
5,058 Expert 4TB
@pradeepjain
Not directly, no. AUTO_INCREMENT only works on integers.

You could create a function that would get the next value for you and use that instead of an AUTO_INCREMENT field.

I wouldn't recommend it tho. You shouldn't format the data like that before inserting it. That sort of thing should be done on the way out, preferably by the front-end code (or in a simple query, like I posted before).
Sep 10 '09 #5
pradeepjain
563 512MB
so which is the best way to generate ID numbers!!
1. remove auto_increment .
Store a basic value as patient001 and then get the value from DB and then increment and send it to DB again for next record

or

2 . let it be auto_increment only !! while displaying to user prefix some text and show it to user!
Sep 11 '09 #6
Atli
5,058 Expert 4TB
#2

There is no good reason for storing "patient001" in the database rater than "1".
Keep the database as simple as possible and do stuff like that (adding "patient") in the applications that require it.

I mean, what if, in the future, a second application was to use the same database, but needed the output to read "client001" rather then "patient001"?
By storing the number only, that is a piece of cake. By storing the "patient" prefix, it becomes a big mess.
Sep 11 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

41
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there...
0
by: Neil | last post by:
Hi, I'm getting some strange results using the autoincrement column on my datatable. I'm populating a datatable with data from my database and displaying this in a datagrid. The first time I get...
6
by: Dennis | last post by:
I have set a DataTable and one of the columns I set "AutoIncrement" to True. I then populate the Table by setting the columns to values then add the row to the table. I inadverently set the...
6
by: Michael | last post by:
I am trying to create an access database within Net 2003 using the ADOX library which works fine except when I try to add the AutoIncrement property to the ContactId column. I am experiencing a...
5
by: JC Voon | last post by:
Hi: How to reset the autoincrement value generated by DataTable ? I've master and detail table, the detail table has a autoincrement column, each time i add a new master record, i need to...
6
by: jimryder | last post by:
Hi, The following snippet: (ds is a populated dataset) string sXSLT = @"C:\XML\template\template.xsl"; string sTemp = @"C:\XML\temp\temp.xml"; string sOutput = @"C:\XML\output\output.xml";...
1
by: Mike | last post by:
I have a form that has an embedded subform (Datasheet View) that are linked based on a 1-many ID field. I have a field (SET) in my embedded subform that I want to Autoincrement starting with...
4
by: Tim | last post by:
Hello All, I could use some help on an error that is just now popping it's head up. Seems that the autoincrement numeric has hit 32,767. The autoincrement is used in various locations in the...
1
rizwan6feb
by: rizwan6feb | last post by:
I have a DataTable with thousands of records, i want to show these records on per page basis ( i.e a DataGridView showing first 20 records and next button to show next 20 records ...) To achieve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.