mySQL 用指定的列列表替换 View 中的通配符

标签 mysql view

创建 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/

相关文章:

android - 来自服务的 dispatchKeyEvent

java - Spring Boot不支持请求方法 'POST'

java - 数据截断: Data too long for column 'sql_stmt' at row 1

c# - 如何使用c#添加递归函数从Mysql获取列

sql - 如何在 MySQL 中重命名索引

php - 如何按列名分组并确保查询检索到最后更新

android - 将字符串传递给 setContentView?

php - 如何从mysql中选择一篇文章及其评论?

android - setBackgroundResource 和 setBackgroundDrawable 有什么区别

Android:缩放 ImageView 及其 onDraw() 项目