I want to add a new column to an existing mysql table, where the new column is a unique integer number for each unique value of an existing column in the table. For example, if the existing column has unique values A and B (and there might be 50 rows of each of A and B), then add a new column with values of 1 and 2 in each row where there is an A and B, respectively.
well, it require two commands
ALTER TABLE your_table ADD COLUMN your_column INTEGER UNIQUE;
And then for each column record, you create an update statements to do so, like:
UPDATE your_table SET your_column = 1 WHERE column = 'A'
UPDATE your_table SET your_column = 2 WHERE column = 'B'
Or you create a procedure for that, if the records are many.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With