创建 View 后(简化)如下:
create view testView as
select t1.* from table1 t1
join table2 t2 on t1.id = t2.id
where t1.value = someValue
当尝试编辑它时,通配符已被替换为表的实际列名。
这对我来说很烦人,因为当新列添加到表中时,我需要手动将它们添加到 View 中,或者保存创建脚本,然后在表修改后重新执行它。
有没有办法保留通配符进行编辑?在 MSSQL 中,编辑 View 时会保留通配符,我只需执行 sp_refreshview [viewname] 即可更新 View 以包含表中的任何新列。
最佳答案
来自MySQL documentation对于 CREATE VIEW
:
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.
所以简短的答案是否定的,您不能保留通配符。
关于mySQL 用指定的列列表替换 View 中的通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12109306/