Chris Watts
Chris Watts

Reputation: 6715

Determine the original table of a column in a view

Is it possible to find the name of the table for which a column in a MySQL view belongs?

If a view was constructed as

CREATE VIEW alpha_view AS
    SELECT alpha.col1, alpha.col2, beta.col2 FROM alpha
    INNER JOIN beta
        ON alpha.col1=beta.col1;

then when I edit, I want to only affect alpha.col1 and alpha.col2 as beta.col2 is derived from another table.

I assumed the easiest way of knowing whether it's editable or not comes from knowing if the original table matches the view's FROM clause.

Is this even possible, or should I just make a list of editable columns for my parsing script?

Upvotes: 1

Views: 69

Answers (1)

Alma Do
Alma Do

Reputation: 37365

Yes, it is possible. Just use aliasing (via AS keyword) to give different name for result column.

CREATE VIEW alpha_view AS
SELECT alpha.col1 AS a_col1, alpha.col2 AS a_col2, beta.col2 AS b_col2 FROM alpha
INNER JOIN beta
ON alpha.col1=beta.col1;

Upvotes: 2

Related Questions