views:

102

answers:

2

On redesigning a MySQL database I came up with an idea: creating a VIEW which can be altered when a TRIGGER (on UPDATE of other table) runs, using information selected from the INFORMATION_SCHEMA database. Hence we could have a view of whichever columns might be necessary at runtime. Since ALTER TABLE is illegal inside triggers, the setting up of the view would have to be done by updating the INFORMATION_SCHEMA database directly.

Can this be done with SQL alone or I'm missing something important? Any comments on possible performance problems?

+1  A: 

ALTER VIEW may not be able to be used in a trigger, but CREATE OR REPLACE VIEW is not on the restricted list...

R. Bemrose
That's definitely nicer than messing with the schema...
slipbull
+1  A: 

It's perfectly legal, just slow to generate the view.