views:

662

answers:

2

I want to add a new column to a table in MySQL database that should get the value of another column in the same table. Is this possible? If so, how do you do it?

Thanks!

+3  A: 

Starting with MySQL 5.0.2 you can write a stored procedure linked to a TRIGGER which can examine the new column each time a row is inserted, and automatically copy the other column's value into the new column if no value was supplied for the new column.

Alnitak
Thanks for the comment. I was originally thinking triggers as well but want to stay away from them. Since this is not very important for my immediate needs, I will just assume that its not possible in MySQL by default.Thanks again!
A: 

create a view, and you can select the same column twice and give it different name, then the application can use the view instead use the table directly.

Ben