SQL Server:可以从 CLR UDF 中调用更新表的存储过程 [英] SQL Server: can a stored proc that updates tables be called from within a CLR UDF

查看:35
本文介绍了SQL Server:可以从 CLR UDF 中调用更新表的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么,但是不允许 CLR 用户定义函数更新表.

I don't know why, but CLR User Defined Functions are not allowed to update tables.

是否可以通过从 CLR UDF 调用存储过程来为它更新表来解决此限制?

Is it possible to work around this restriction by calling a stored procedure from the CLR UDF that updates tables for it ?

推荐答案

它不是 CLR UDF,而是任何 RDBMS UDF 函数,顾名思义,不能改变数据库的状态,即搞:

It is not CLR UDF, it is any RDBMS UDF function, by definition, cannot change the state of a database, i.e. engage:

  • 删除、插入、更新(即 DML)语句,
  • 调用存储过程,
  • 永久更改服务器环境变量的值,

  • 以及使用对非确定性(相同输入返回不同结果)函数的调用(如 GETDATE()、NEWID() 等)

更新:
糟糕,SQL Server 2008 放宽了对使用非确定性函数的限制.如果 UDF 使用非确定性,则将其视为非确定性的.

Update:
Oops, SQL Server 2008 relaxed the restrictions on use of non-deterministic functions. If UDF uses non-deterministic, then it is treated as non-deterministic.

可以通过以下方式检查:

One can check it by:

SELECT OBJECTPROPERTY(OBJECT_ID('dbo.FunctionName'),'IsDeterministic') 

这篇关于SQL Server:可以从 CLR UDF 中调用更新表的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆