Moti
Moti

Reputation: 927

SQL query to update multiple tables with same column name

I have a database that include many tables with have same column name and I would like to run a SQLITE3 query to change the values of all tables.

  Table XXX (id integer, name text);
  Table YYY (id integer, .....);
  Table ZZZ (id integer, .....);
  Table....

To run a query on all table which jave a field name "id" I used the query: select name from sqlite_master where sql like ('%id%');

But, how could I use the UPDATE query with the list of tables?

Upvotes: 1

Views: 1497

Answers (2)

pkoulianos
pkoulianos

Reputation: 187

You can use a trigger in order to update as many tables you want after insert in a single table .

example trigger

CREATE TRIGGER update_tables
AFTER INSERT ON XXX
BEGIN

INSERT INTO YYY (new.id,new.integer);
INSERT INTO ZZZ (new.id,new.integer);

END

Upvotes: 0

wvdz
wvdz

Reputation: 16651

Not possible with regular sql without simply listing all table/column combinations.

Possible solutions could be functions/procedures or other ways to execute dynamically generated sql.

Upvotes: 1

Related Questions