INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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!!!

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

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

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

(OP)
Sorry it took me so long to reply. Thanks vacunita. I'm going to try it this week.

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

(OP)
It worked beautifully. Thanks again Phil.

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close