0

I have a table with 62 columns and 22k rows. I need to change every row of the first column. I have the new data on a text file. How can I do it? I have tried with 'replace' and 'update' but I can't find the way to substitute using the text file and it's impossible to change it manually.

JYelton
  • 35,664
  • 27
  • 132
  • 191
  • Are you saying your text file has 22k lines where each represents the new data for the first column in the sql table? – JYelton May 05 '22 at 18:04
  • 1
    1. You load your text file into its own table. 2. You write an UPDATE statement that joins your new table to your current one including the relationship between these two tables. If you share sample data and desired results after this update we can help you write that UPDATE statement. – JNevill May 05 '22 at 18:07
  • Jyelton, Yes exactly. The text file that I want to introduce have also 22k values one for each row – Marc Romero May 05 '22 at 18:44
  • JNevil, the second table needs to have a common field with the old one to join them right? – Marc Romero May 05 '22 at 18:45

1 Answers1

0

Let's say your original table looks like this (it would be helpful if you'd post snippets or samples):

Name ID
==== ==
Mary  1
John  2
Dave  3
Suzy  4

And your text file:

Mari
Juan
Daav
Suzi

If you know that the sequence of lines in the text file is the same as the table (or you can arrange the table in that sequence by query), then do the following:

Create a temporary table by importing the text file. If necessary add a unique ID that you can use as a join criteria.

Write an update query that links the tables as needed:

UPDATE table a
LEFT JOIN temp_table b
ON a.id = b.id
SET a.name = b.name;

Research how to add a primary or unique key to either table as needed to create the join condition.

JYelton
  • 35,664
  • 27
  • 132
  • 191