473,585 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help of auto_increment

Hi, how can I add char to auto_increment? For example, the
auto_increment is for integer, I want to add a character at the front
of that number. Ex:
create table abs (UserID INT(3) NOT NULL AUTO_INCREMENT, name varchar(15),
primary key(UserID));insert into abs(name) VALUES ('Elton'), ('Andy'), ('Peter');
select * from abs;


The output is:
+ -------+--------+
| UserID | name |
+--------+--------+
| 1 | Elton |
| 2 | Andy |
| 3 | Peter |
+ -------+--------+

The output I want is:
+ -------+--------+
| UserID | name |
+--------+--------+
| U1 | Elton |
| U2 | Andy |
| U3 | Peter |
+ -------+--------+
Notice that I added 'U' at the front of the UserID, is it possible to
do that?
What is the command for that? Thanks
Best Regards,
Hau Jyn
Jul 20 '05 #1
2 1916
hjyn wrote:
Hi, how can I add char to auto_increment?


As far as I can tell from the documentation, auto_increment can be
applied only to integer type columns.

If you want a 'U' at the start of the identifier, you can do it as an
expression in the select:

SELECT CONCAT('U', abs) AS abs, ...
FROM abs;

Other options might be to avoid the use of auto_increment, and provide a
unique primary key value manually. Or else define an integer field as
the auto_increment field, and then another field as the identifier with
the character prefix. Then, every time you insert a value to your
table, follow that operation with an update forcing the second
identifier column to have the value you describe:
UPDATE abs SET abs2 = CONCAT('U', abs);

Regards,
Bill K.
Jul 20 '05 #2
Thanks Bill, your solution help me a lot.

Regards,
Hau Jyn
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1284
by: Frank | last post by:
This one has me pretty stumped at the moment. I've tried variations with MySQL IF() statements but can't quite get it right. How can I select all of the records of the table 'items' that are active. Restricted such that if there are items active for the subcategory and the parent category *only* the items of the subcategory get returned and...
9
3317
by: Bart Van der Donck | last post by:
Hello, The first column of my table is AUTO_INCREMENT. I fill my table with 5 records with a blanco value in their first field. The first column of my table will then hold the values 1,2,3,4,5 (top>down). Then I erase those 5. Then I add a new record with a blanco first value. It will get number 6.
0
1487
by: Mike Chirico | last post by:
Hopefully this will help someone... Helpful Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Last Updated: Fri Apr 16 11:47:34 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download Format is better on the above link. I'm looking for...
0
1766
by: Shailesh | last post by:
I made a MyISAM table on mysql 4.0.18 NT with auto_increment column started at 2147483646. The third row I insert fails as expected because the integer range is maxed out. However, if I delete the topmost row, and then re-insert a row, the topmost value is reused. This contradicts the documentation. ...
2
492
by: hjyn | last post by:
Hi, how can I add char to auto_increment? For example, the auto_increment is for integer, I want to add a character at the front of that number. Ex: >create table abs (UserID INT(3) NOT NULL AUTO_INCREMENT, name varchar(15), primary key(UserID)); >insert into abs(name) VALUES ('Elton'), ('Andy'), ('Peter'); >select * from abs;
4
2694
by: Chefry | last post by:
I'm trying to set up an off the shelf script and keep getting an error. My host set up the mysql on my site and I changed the variables I had to in the settings.php file but I keep getting the following errors Warning: mysql_pconnect(): Access denied for user: 'ODBC@localhost' (Using password: NO) in...
7
1679
by: Jim | last post by:
I need help on a query. There is a common titles database for several radio stations Some titles are enabled and some are not enabled for each station. Example of some tables: Titles Stations Station_Titles ------ -------- ------------- id id Station_ID Title StationName Title_ID
3
1472
by: Pir | last post by:
I have a created a table 'data' with two columns: id, name. +-------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | name |...
3
1425
by: Marty | last post by:
OK, I'm new at all of this and have decided to take on a project to learn. We have a fishing club that has 23 members. Each weak we go fishing in various places for 4 hours. Not together, usually 2 to a boat and it's your choice where to go. I want to build a database / website that the individual fishermen can go to and log there success....
5
3865
by: odntuk | last post by:
Hello, I'm new to database development and need your help. Although, I'm new I know that storing multiple entries into a database field is a horrible idea. Therefore, I'm trying to implement cross-reference/look-up tables. Here's the problem I'm trying to solve... I'm working on a restaurant guide site with restaurants having multiple...
0
7908
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.