SQL更改递归函数
我正在使用 SQL Server 2008。
我想对递归函数执行 ALTER。更改添加了参数,似乎对此感到窒息。
该函数没有依赖项,因此我可以安全地执行 DROP+CREATE,但是当该函数具有依赖项时应该做什么?
错误信息是这个
消息 8144,级别 16,状态 2,服务器 TESTSERVER,过程 fn_IsOwnerFunction,第 177 行 过程或函数 dbo.fn_IsOwnerFunction 指定的参数过多。
该消息又出现了几次,每次都是针对函数引用自身的行。注:指新版本参数较多。 DROP+CREATE 后,ALTER 脚本可以正常运行,不会出现错误。
I'm using SQL Server 2008.
I want to execute an ALTER on a recursive function. The alter adds parameters, it seems to choke on that.
The function has no dependencies so I can safely do a DROP+CREATE, but what should be done when the function does have dependencies?
The error message is this one
Msg 8144, Level 16, State 2, Server TESTSERVER, Procedure fn_IsOwnerFunction, Line 177
Procedure or function dbo.fn_IsOwnerFunction has too many arguments specified.
The message appears a few more times, each time for a line where the function refers to itself. Note: it refers to its new version that has more parameters. After DROP+CREATE, the ALTER script works without errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以删除其他函数或存储过程中使用的函数。
当然,删除/创建函数后,您需要更改函数和使用该函数添加新参数的存储过程。
It is ok to drop a function that is used from other functions or stored procedures.
Of course, after you drop/create the function you need to alter the functions and stored procedures that uses the function to add the new parameters.
如果错误是“指定了太多参数”,那么您的调用代码传递了太多参数。这可能意味着您之前运行的 ALTER FUNCTION 语句实际上并未完全处理。这可能是因为语法错误或类似的原因。再次运行 Alter 语句并检查那里的错误消息。
编辑:
在 CREATE FUNCTION 语句之前添加 DROP FUNCTION 语句:
If the error is "too many arguments specified" then your calling code is passing in too many parameters. This could mean that the ALTER FUNCTION statement you ran earlier didn't actually process fully. That could be because of a syntax error or something similar. Run the Alter statement again and check the error message there.
EDIT:
Add a DROP FUNCTION statement before your CREATE FUNCTION statement: