Unexpected @@rowcount behavior inside an UDF in MS SQL 2019

时光总嘲笑我的痴心妄想 提交于 2020-01-23 01:39:06

问题


here's my sample code

drop function rowcount_test
go
CREATE FUNCTION dbo.rowcount_test () RETURNS INT AS
BEGIN
    DECLARE @v INT
    SELECT @v = 1
    return @@ROWCOUNT
END
GO
grant exec on dbo.rowcount_test to public
go
SELECT dbo.rowcount_test()

It gives 1 when executed by mssql 2017 (and earlier)

It gives 0 when executed by mssql 2019

It gives 1 when executed by mssql 2019 (Standard edition) with a db put to the 2017 compatibility mode

It's never been a problem before... Is it a kind of setting affecting the code or a kind of bug in MSSQL 2019?


回答1:


Scalar udf inlining yet again, rather buggy

SELECT dbo.rowcount_test()

OPTION (USE HINT('DISABLE_TSQL_SCALAR_UDF_INLINING'));


来源:https://stackoverflow.com/questions/58952917/unexpected-rowcount-behavior-inside-an-udf-in-ms-sql-2019

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!