Connecting Tech Pros Worldwide Help | Site Map

auto_increment

Newbie
 
Join Date: Apr 2009
Posts: 24
#1: May 11 '09
i am designing a website for travel agency. the requirement is everytime any user books anything( car, hotel etc) a reservation id is generated for internal use. i want to start the resv_id with 'resv' and then a number following it. please tell me how to do it using auto_increment. is there any other way to do that? i have a table with attributes user_id ( created by the user) and resv_id ( generated) and the primary key is the composite key .please help.urgent!!
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: May 11 '09

re: auto_increment


No need to store the 'resv' part in the database. It just add clutter. Just add the 'resv' part before you display the id to the users.
Newbie
 
Join Date: Apr 2009
Posts: 24
#3: May 11 '09

re: auto_increment


no this is not to display to the user. it will be saved in the database only. if it is not possible , then i would go for numeric data only.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: May 11 '09

re: auto_increment


If there is no need to display it then why should you worry about how it looks like?
Pre pending that text just adds unnecessary characters to the database.
Newbie
 
Join Date: Apr 2009
Posts: 24
#5: May 12 '09

re: auto_increment


yes perhaps u r right. actually i was thinking as per the requirement documentation. but i also think choosing only the auto_increment function will do the work. thanx for consulting :)
Member
 
Join Date: Dec 2006
Location: Pune
Posts: 50
#6: May 13 '09

re: auto_increment


Yes You can add prefix in Autoincrement..

Make a CHAR (or VARCHAR) AUTO_INCREMENT column with mandatory
PREFIX. MySQL would then assign values that start with the prefix,
followed by a sequential number. The numbers could be chosen either
from the whole INT set sequentially for all prefixes, or individually
for each prefix, effectively multiplying the number of possible
values - I don't really care about that. Example of proposed syntax:
CREATE TABLE example2 (id VARCHAR(14) AUTO_INCREMENT PREFIX 'ISP',
other_column VARCHAR(100));
This would create id values of: 'ISP1', 'ISP2' etc.

Regards,
Sandeep Agarwal
Newbie
 
Join Date: Apr 2009
Posts: 24
#7: May 13 '09

re: auto_increment


yes i tried this one but it shows some error like
incorrect column specifier for column 'id' , error no 1063.
just for information , i m using mysql 5.1.
Reply

Tags
auto_increment