I'm new in MySQL. I have table "books", in table is column ISBN. How can I update this column for all rows? I have to complete all the lines with ISBN according to the key: BOOK0001, BOOK0002, BOOK0003... (where BOOK is a preffix). I have something like this for this moment but I'm not sure if I mean it right:
SET @isbn=0;
UPDATE books SET isbn = (@isbn:=@isbn 1) ORDER BY isbn;
Can I count on a hint?
CodePudding user response:
UPDATE books
CROSS JOIN (SELECT @isbn:=0) init_var
SET isbn = CONCAT('BOOK', LPAD(@isbn:=@isbn 1, 4, 0));
