0

All:

I am pretty new to SQL, I wonder how can I update certain field value across multiple tables in SQLITE3 database?

For example:

the database is company.db, inside it, there are 50 tables, each table has a column called company_name, now some company's names changed, so I need to update that info in all tables, I wonder how to do it in SQL?

Thanks

Kuan
  • 11,149
  • 23
  • 93
  • 201
  • You'll need to update each table individually. To make this easier in the future, consider replacing the company name with a company id and adding a table mapping company ids to company names. Then all you need to do is update that table when a company changes name. – glibdud Apr 06 '18 at 20:41
  • @glibdud Thanks, So there is no such syntax that I can do like `for(tablename in tablenames) { update tablename set company_name="some name" where company_name="target name" }` ? – Kuan Apr 06 '18 at 20:44
  • 1
    Not strictly in SQL, but see [this question](https://stackoverflow.com/questions/16160952/how-to-apply-a-sqlite-command-to-all-tables) for a way to generate a SQL file you can apply to your database. – glibdud Apr 06 '18 at 20:47

0 Answers0