如何从表中添加/删除列时更新mysql视图?
问题描述:
I created a table and then some views for the table. Now i altered the table to add another column in it.But the views are not updated.It doesn't have the column that is added in the table.Is there any way to modify view structure automatically?
我创建了一个表,然后为表创建了一些视图。 现在我更改了表以在其中添加另一列。但是视图没有更新。它没有在表中添加的列。是否有任何方法可以自动修改视图结构? p>
答
You can use alter view
command to modify the view and change the columns.
For example, if your view is view1 and table is table1, you can do something like this:
ALTER
VIEW view1 col1, col2, col3, new_col
AS select tcol1, tcol2, tcol3, new_tcol from table1
Here is the documentation for the full syntax for mysql.
Hope this helps!