473,508 Members | 2,227 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 1906
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
1278
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...
9
3311
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...
0
1482
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...
0
1752
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...
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...
4
2689
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...
7
1678
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 ...
3
1465
by: Pir | last post by:
I have a created a table 'data' with two columns: id, name. +-------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra |...
3
1420
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...
5
3858
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...
0
7132
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...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
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...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4720
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...
0
3211
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...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
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 ...
0
432
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...

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.