I have about 25 tables that I would like to update with random data that was selected from a subset of the data. I would like the data to be chosen at random, but significant - like changing all the first names in the database to new names in a random order. Therefore, I do not want random garbage in the fields, I would like to get it out of the temporary table, which is populated ahead of time.
The only way I can do this is with a loop and some dynamic sql.
- insert pick-in names into temp table with id field
- foreach table name in tables list:
- build a dynamic sql that updates all the names for the name randomly selected from the temp table based on rand () * max (id) from the temp table
But at any time, I think that the “loop” in SQL, I suppose I'm doing something wrong.
There are many denormalized tables in this database, so I think I need a loop (the first name fields are scattered across the database).
Is there a better way?
source share