0

I have a table with 381 records with the columns id,name,dept_id.

How would I introduce a column called row_id with numbers that count from 1-381 (to uniquely identify each row and they need to auto-increment from this point afterwards).

I would need to write this in MySQL. The only other way I can think of is manually entering this but it would take too long.

methuselah
  • 12,766
  • 47
  • 165
  • 315
  • 4
    How is `row_id` going to be different than the existing `id`? In general, you are asking about a possible solution to a problem, while you should be asking directly about the problem you want to solve. – Jon Feb 12 '13 at 11:04
  • 1
    why do you need that extra column? – जलजनक Feb 12 '13 at 11:07
  • Take a look at this post http://stackoverflow.com/questions/3126972/mysql-row-number – istepaniuk Feb 12 '13 at 11:07

1 Answers1

1

add a new column alter table table_name add column row_id int() then execute this command SELECT @i:=0;UPDATE table_name SET row_id = @i:=@i+1then make it primary key and set it as auto increment

Raul
  • 579
  • 1
  • 5
  • 17