I have a large table of data with a new field added called uniq_id what I am looking for is a query I can run that will update and increment this field for each row, without having to write a script to do this.
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What other columns does the table have? If you define the new column with
AUTO_INCREMENTMySQL will fill it with sequential values starting from 1. There’s a catch though: the column has to be a key, or at least a part of the key (see the documentation for details). If you don’t have a primary key in the table already, you can simply do this:If you can’t change the keys in the table and just want to fill the values of the new column as a one-off thing, you can use this
updatestatement:(
coalescereturns its first non-null argument; it effectively establishes the value of the column for the first row.)