Skip to main content

Thread: mySQL add auto_increment?


is there way edit existing table , add auto_increment field? have table, , want each row have it's own "id." hashing multiple columns, think easier have auto increment field. have drop table , create new one?

hi, may able rebuild. i'm assuming have primary key in table? having quick stab @ adding auto increment attribute gives me this...

code:
there can 1 auto column , must defined key

there way add row, not auto incremented (as have mess around primary key have knock on effects). 1 way this:

add new column:
code:
alter table mytable add idcol int not null;
then create counter:
code:
set @count = 0;
then update rows include new number id:
code:
update mytable set idcol = @count:=@count+1;
the problem is, won't automatically increment new tuples when added unless use count variable when inserting


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] mySQL add auto_increment?


Ubuntu

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account