[英]How to refresh the definition of a T-SQL user-defined function after a dependent object is redefined?
Consider the following sequence of events: 请考虑以下事件序列:
I can just re-run the script that created GetFoo in the first place and all will be well; 我可以重新运行最初创建GetFoo的脚本,一切都会好起来。 but that's problematic for reasons I won't go into. 但这是有问题的,原因是我不愿讨论。 Is there any other way to refresh the definition of a user-defined function so that it's in sync with its dependent objects? 还有其他方法可以刷新用户定义函数的定义,使其与其相关对象保持同步吗?
Short, easy answer is No . 简短而简单的答案是“ 否” 。
You have to redefine the RETURN TABLE
statement in Tabular UDF, GetFoo()
您必须在表格UDF中重新定义RETURN TABLE
语句GetFoo()
whenever the definition of v_Foo
changes. 每当v_Foo
的定义更改时。
But there is a way to get around it (translated as not practical). 但是有一种解决方法(翻译成不实际的方法)。
DDL
trigger on ALTER_VIEW
event. 在ALTER_VIEW
事件上创建DDL
触发器。 GetFoo()
. 然后使用动态SQL创建GetFoo()
。 It would be nice to see the definition of the function. 很高兴看到函数的定义。 All you've said is it is using SELECT *. 您所说的只是使用SELECT *。 Can you be more specific? 你可以说得更详细点吗?
You also forgot to tell us what version of SQL Server you are using. 您还忘了告诉我们您使用的SQL Server版本。 If >= 2005, have you looked at sp_refreshsqlmodule
? 如果> = 2005,您是否看过sp_refreshsqlmodule
?
Curious what your reasons are for insisting on SELECT *. 好奇您坚持SELECT *的原因是什么。 Lots of discussion about it here, but the cons still outweigh the pros by a large margin, IMHO: 在这里有很多讨论,但是缺点还是很大,IMHO:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.