Add Letter in a field with 20000 lines

Asked

Viewed 620 times

0

I have a table produto filled with 20000 products and I need to add one o in the first character of the field codigo all-line.

How can I do this with Mysql?

  • 2

    Welcome to Stackoverflow! Please explain the problem better, and if possible include a example of code that reproduces what is happening, 'cause it’s not clear what you’re asking. See Help Center How to Ask.

  • Want to add an "O" in a table field? Or a file? What is the connection to mysql?

  • it is simple to have 20000 references all with their different code 1000 1001 1002 and want to renumber to o1000 o10001 o10002 so susceptibly that is to separate old references from new references

  • @Andrefrancisco You tagged the question with mysql and insert, leading people to think this is a database question... Is this, or is it a text (file) file? Or something else? And finally: what programming language are you using?

  • but it’s a mysql database is a table that I have product codes that I need to renumber them with a precise left letter of the instruction for the input of that letter

  • So it’s not a file as it says in the question it’s a table, right?

  • 2

    yes and a table called product in which I have the code field I want to add a letter in the records all! I’m sorry I’m still a bit Noob in this

  • @Andrefrancisco see my edition and if that’s what you want to ask.

  • AND THAT’S RIGHT THANK YOU

  • 1

    What is the type of this field?

  • The product code is Foreign Key in some table?

Show 6 more comments

1 answer

3

Considering that the column is text type, and that this change will not cause harmful side effects (such as breaking foreign keys), the command is simple:

UPDATE produto
SET codigo = CONCAT('o', codigo);

As in the question there are the unknowns I mentioned above, I recommend taking a backup of the database before running this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.