在 MySQL 中,保存以下 View 后:
CREATE VIEW MyView AS SELECT * FROM MyTable;
如果我编辑MyView,星号就会消失,并且 SQL 包含所有字段名称。例如:
ALTER VIEW MyView AS SELECT field1, field2 FROM MyTable;
当MyTable添加了新字段时,我希望 View 输出也显示这些新字段。如何防止星号被文字列名称替换?
最佳答案
View 是虚拟表的存储查询。因此更改原始表不会影响虚拟表 因此要更新 View ,您需要删除它然后重新创建它
DROP VIEW MyView
然后
CREATE VIEW MyView AS SELECT * FROM MyTable;
The view definition is “frozen” at creation time, so changes to the underlying tables afterward do not affect the view definition. For example, if a view is defined as SELECT * on a table, new columns added to the table later do not become part of the view. the source
关于mysql - 在 View 中动态获取表中的所有列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46999600/