在 SQL 函数中插入查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5088252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert query in SQL Function
提问by Robin clave
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
我可以在 SQL Server 2008 中的 Function 中编写插入查询吗?如果我尝试过,我会在函数内收到无效使用副作用运算符“INSERT”的错误。请帮帮我。但我希望它是一个函数,而不是一个存储过程
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
回答by Hans Ke?ing
Quote from here:
从这里引用:
User Defined Functions cannot be used to modify base table information. The DML statements INSERT, UPDATE, and DELETE cannot be used on base tables.
用户定义函数不能用于修改基表信息。DML 语句 INSERT、UPDATE 和 DELETE 不能用于基表。
So you can't do an INSERT in a function.
所以你不能在函数中做 INSERT。
You might want to explain WHY you don't want to use a procedure.
您可能想解释为什么不想使用过程。