在 SQL 函数中插入查询 [英] Insert query in SQL Function

查看:35
本文介绍了在 SQL 函数中插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 SQL Server 2008 中的 Function 中编写插入查询吗?如果我尝试过,我会收到一个错误,提示在函数中使用副作用运算符INSERT"无效.请帮帮我.但我希望它是一个函数,而不是一个存储过程

Can i write a insert query inside Function in SQL server 2008. If i tried, im a getting an error of Invalid use of side effecting operator 'INSERT' within the function. Please help me out. But i want it to be a function, not a stored procedure

Create function EFT_DL_FUNC_AUDTI_BATCH_START (@i_db_name varchar(20))
returns int as
begin
    insert into table_name(db_name) values (@i_db_name)
    return 0
end

推荐答案

引用自 这里:

不能使用用户定义的函数修改基表信息.这DML 语句 INSERT、UPDATE 和DELETE 不能用于基表.

User Defined Functions cannot be used to modify base table information. The DML statements INSERT, UPDATE, and DELETE cannot be used on base tables.

因此您不能在函数中执行 INSERT.

So you can't do an INSERT in a function.

您可能想解释为什么不想使用过程.

You might want to explain WHY you don't want to use a procedure.

这篇关于在 SQL 函数中插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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