0

Been searching on Google for a while now without finding the answer to my problem. I have like 10 tables where 5 of them contains 150 rows. I want to add 15 rows to these 5 tables, is there any simple solution for this? I know it's easy to add the rows manually but I want to know anyway. What I'm looking for is something like this:

INSERT INTO all_tables VALUES (col1, col2, col3) WHERE row_number() = '150'

Is it possible? Thanks in advance!

Cheezen
  • 179
  • 1
  • 2
  • 12

2 Answers2

4

You can only target updates to one table at a time, which must always be specified by name. Also, you cannot specify a WHERE clause on an INSERT. Your best bet is probably to write one INSERT and copy and paste for the rest.

onedaywhen
  • 55,269
  • 12
  • 100
  • 138
ron tornambe
  • 10,452
  • 7
  • 33
  • 60
1

You could:

  1. Loop through a list of the relevant table names.
  2. Run a dynamic query like select count(*) into @c1 from SpecifiedTable against the relevant table, returning the count into a declared variable.
  3. If the returned value is 150, run another dynamic query to insert the relevant values into the specified table.

You can find out more about dynamic queries and returning values from them in MySQL here. If this is a once-off, you will probably find it easier to do it manually.

Community
  • 1
  • 1