-1

I have an empty MySQL database that has around 30 tables related all over the place. Is there a way to easily insert one record in this database without manually having to go through each table?

Rod
  • 14,529
  • 31
  • 118
  • 230
  • 2
    The answer is maybe. If you can find a table which has no foreign key constraints in it, you can probably do an insert into this table. Finding this table will involve manual labor, unless you know how to interrogate MySQL for constraints on tables. But, there is not enough information here for me to give you a better answer than that. – David Buttrick Jun 22 '18 at 21:18
  • You do not insert rows in a *"database"*, you insert them into a table. If you want to insert one row in each table, you will need to have one insert per table, unless you can construct a one-to-one join between all of the tables, which would probably be more intensive/work than just creating the individual inserts. – Sloan Thrasher Jun 22 '18 at 23:31

1 Answers1

0

INSERT creates a row in only one named table. You have to insert to each table, one at a time.

You can start a transaction and run multiple statements within the scope of the transaction. For instance, a series of inserts to 30 tables. Then commit the transaction. This ensures that no other concurrent transaction can view your new data midway through the sequence of inserting to the multiple tables.

This sort of question, or similar ones, have been asked before:

I didn't close your question because it's not clear why you are asking it, so I can't be sure any of the others are exact duplicates of your question. But they're clearly related.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828