0

I don't know if this is possible but I'll explain what I need.

What I've got: - Table1: A users table - Table2: A table which contains items definitions - Table3: A table which stores for each user, amounts of items (defined in previous table)

With this tables structure, what I need to achieve is that when I add a row in Table2 (items definitions), automatically Table3 (users items) updates according to Table2 columns.

Example:

enter image description here

If I deleted a row in Table2, this would be the action:

enter image description here What's the best way to do this?

pnuts
  • 58,317
  • 11
  • 87
  • 139
ProtectedVoid
  • 1,293
  • 3
  • 17
  • 42
  • 1
    look into triggers. And restructure table3 into a [Junction Table](http://stackoverflow.com/a/32620163/). Your table3 is de-normalized. What are you going to keep doing, adding new columns to table3 constantly? – Drew Nov 20 '15 at 23:08
  • @Drew That's what I want to avoid. A two table maintenance. The point is to add rows to Table2 and automatically those rows will become columns in Table3. That way I can count how many items have each user (as an example). I'll check Junction Table definition. Thanks. – ProtectedVoid Nov 20 '15 at 23:18
  • If you are saying that you want to add a row to t2, and the textual value of a column in the new row becomes a column name in t3, then I say this is about the poorest of concepts. And I wish you luck with that (and any peer blessing) :) But who cares about peer blessings half the time. They just want to do it their way – Drew Nov 20 '15 at 23:20
  • @Drew The first line of my question makes clear that I'm asking this because I don't know how to achieve this (yes, my SQL knowledge is low). I need a response that guides me how to do it, not a "sarcastically reply". Thanks again. – ProtectedVoid Nov 20 '15 at 23:25
  • I have a Junction Table link in comment line 1. I wrote it to help people. No sarcasm intended. Just a reflection on what people tend to do anyway. – Drew Nov 20 '15 at 23:29
  • @Drew I'll study your answer as it's complex, but I'm sure It will help me. Thanks. – ProtectedVoid Nov 20 '15 at 23:33
  • my pleasure. Bounce your drafts by us – Drew Nov 20 '15 at 23:36

0 Answers0