I am trying to create a function wrapping change_tracking_min_valid_version(object_id), to simplify queries when using synonyms instead of table names. Something like this:
CREATE FUNCTION MY_CHANGE_TRACKING_MIN_VALID_VERSION(@synonym VARCHAR(100))
RETURNS BIGINT
BEGIN
RETURN (SELECT CHANGE_TRACKING_MIN_VALID_VERSION(OBJECT_ID(base_object_name))
FROM sys.synonyms WHERE name = @synonym);
END
I have tried getting the base object name separately, to be able to drop the select part of the return statement, i.e.
set @retval = CHANGE_TRACKING_MIN_VALID_VERSION(OBJECT_ID(@table_name))
MS SQL Server Management Studio produces this error:
Msg 443, Level 16, State 1, Procedure MY_CHANGE_TRACKING_MIN_VALID_VERSION, Line 5
Invalid use of a side-effecting operator 'change_tracking_min_valid_version' within a function.
I do understand that I can't use operations with side-effects in functions, but since I can't seem to find any information about (or understand why there would be any) side-effects of this specific function, my question is:
What are the side-effects of CHANGE_TRACKING_MIN_VALID_VERSION?
(I am using SQL Server 2012.)