0

How to insert, update, delete data with many to many relationed table of MYSQL?

E.g.:

**Structure of my database**
table A -    ID, Field1, Field2, ...
table B-     ID, Field1, Field2...
table Refer- ID, AID,BID

Is there any automatic reflects system in refer table when insert data in tables A or B?

For Example:

If I insert data in Table A with corresponding data in table B it will automatically reflects in Refer table based on Table A and B Relationships.

Please help me. Thanks in advance.

Michal Borek
  • 4,584
  • 2
  • 30
  • 40

2 Answers2

0

You can use the following :

  • delete part you can use ON DELETE CASCADE (example) but the ENGINE used should be InnoDB but then again you can use a trigger for delete also
  • for inserts and updates you can use triggers (example,docs)
Community
  • 1
  • 1
Stephan
  • 8,000
  • 3
  • 36
  • 42