Let's say I create a multi-statement function like this:
CREATE FUNCTION dbo.Test ()
RETURNS @res TABLE (N int NOT NULL CHECK (N >= 0))
AS
BEGIN
INSERT INTO @res
SELECT 1
RETURN
END
That works fine. Then I make a change in the function's body, replace the
CREATE FUNCTION with ALTER FUNCTION, and execute the batch. I get an error:
Server: Msg 3729, Level 16, State 3, Procedure Test, Line 9
Cannot ALTER 'dbo.Test' because it is being referenced by object
'CK__Test__N__5D2E32EB'.
Indeed, if I look at the list of dependencies for the function in QA's
object tree, I can see the check constraint referenced in the error
message.
ALTER FUNCTION works fine if I don't specify the CHECK constraint in the
definition of the @res table.
So it seems that the only way to modify such a function is to drop and
recreate. Is that a known behavior? Is there any particular reason for it?
Thanks.
--
(remove a 9 to reply by email)