SET @i = 0; UPDATE yourtable SET your_int_col = (@i:= @i + 1);
I would imagine that there is an order you want for the resulting sequence. In that case, you should add an ORDER BY clause to cause the update to happen in the specified order.
Of course, new rows added after this won't automatically continue the sequence, so you'd either have to set the correct sequence number as you add new rows or rerun this after adding them. If you do it after, you could restrict the update to the new rows with something like:
SELECT @i:=MAX(your_int_col) FROM yourtable;
UPDATE yourtable SET your_int_col = (@i:= @i + 1) WHERE your_int_col IS NULL;
assuming your_int_col can be NULL, otherwise use WHERE your_int_col = 0;
Michael
A Z wrote:
Hi,
Is there a function to fill an integer column in incremental order (1,2,..,n). Cannot use Auto_Increment as the table has another primary key.
regards
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]