P
P
Phoenixsn2021-04-14 09:37:31
SQL
Phoenixsn, 2021-04-14 09:37:31

How to change data in columns according to a template in multiple tables?

Good morning.

There are several tables (400+), each of them has a different number of columns, but some have a repeating column.

Is it possible to write a query so that it goes through all the tables in the database, searches for a column with a certain name (match) and changes the data there.

There are no problems with replacing these data, there is a misunderstanding with the first part of the task - searching in the database for all tables where there is a certain column.

Example below (values ​​invented).
There are 5 tables, in 4 there is a column "Who changed". You need to go through all the tables, no matter how many there are, check if there is such a column and replace the values.

t1
Name - Address - Phone - Age - Who changed

t2
Car - ID - Who changed - Make - Mileage

t3
Product - Price - Cost price - Who changed - Supplier

t4
Who changed - Product - Dish - Price

t5
Supplier - Address - Contacts - Representative

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2021-04-14
@d-stream

Very much depends on the dialect.
In MS SQL - a bunch of sys. * views including sys.tables (and sys.system_objects) - in general, the issue of identifying tables, fields and modifying them is quite easy to solve using sql tools, including even heavy pk
... same)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question