我可以在SQL Server 2008中的函数内写一个插入查询.如果我试过,我得到一个错误,在函数内无效使用副作用运算符’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
解决方法
引自
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.
所以你不能在函数中执行INSERT.
您可能想要解释为什么不想使用过程.