+ 1
Auto increment for varchar in mysql
it is possible to increment numbers automatically in MySQL. in the same way I want to increment for varchar. I heard we need some trigger but I don't have any idea how to do it and where to write the code for that. any help would be appreciated
8 Respostas
+ 3
http://stackoverflow.com/questions/21145426/php-alphanumeric-auto-increment-insert-into-sql-database
First answer. Exactly what you're trying to do. [Keywords: mysql increment alphanumeric]
+ 2
auto increment is not possible for varchar generally
it is done just adding the word AUTO_INCREMENT in query durring creating table.
CREATE TABLE Students{
ID int AUTO_...
}
you can manually increment it. or convert or during making it by php do like incrementing it by one and inserting ietc it will not be automatic
+ 2
yes that would be possible by server script in PHP you can do like
$new_auto_increment=$last_id_fetched_from_database+1;
$id="BR000".$new_auto_increment;
$query='INSERT INTO Students ID VALUES "$id" ';
you can do that in varchar by automatic incrementing using program
for example last one is 0005 make program that gets it then
new no is 5+1 that is 6
now generates BR00006
and then inserts it after automatic incrementing into the varchar column.
+ 2
yes the stack overflow answer is nice, and it's by SQL only without using script to increment
+ 1
I heard some trigger is used... any idea?
+ 1
There's no way you can increment a varchar i.e. some string in nature, only AUTO_INCREMENT which apply to integers i.e. 1, 2, 3 and so on
+ 1
cool... thanks Sandeep
0
okay... for example my series should be like BR001, BR002... is this possible?