Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a field in a table using a text file and the command line 1

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
0
0
US
I have to update a field in a table if it meets certain criteria. I have 21700 UPDATE statements since the field_name1 and field_name2 are different for each one. Is it possible to have all of these UPDATE statements in one text file and run it from the command line. What do you type on the command line if this is possible?

Text file is named "update_field". Examples of the statements in the file.

UPDATE table_name SET field_name='Y' WHERE field_name1='0988' and field_name2=7950;
UPDATE table_name SET field_name='Y' WHERE field_name1='1055' and field_name2=80010;

Thanks for your help!!!
 
It actually quite possible. IF each Update is on a single line and is terminated by semi colon ";" You can simply pass the file to mysql like this:

Code:
mysql databasename -u username -p < filename.ext

Mysql will execute each statement on the selected Database.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Sorry it took me so long to reply. Thanks vacunita. I'm going to try it this week.
 
It worked beautifully. Thanks again Phil.
 
No problem, glad I could help.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top