I have a table with a PERSISTED
and indexed calculated field (Test
) based on the result of a function (MyFunctionTest
), eg.:
CREATE TABLE [dbo].[TestTable] (
[Id] [int] IDENTITY(1,1) NOT NULL,
[Foo] [int] NOT NULL,
[Test] AS ([dbo].[MyFunctionTest]([Foo])) PERSISTED,
CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED
(
[Id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
MyFunctionTest
is:
ALTER FUNCTION [dbo].[MyFunctionTest]
(
@foo int
)
RETURNS int
WITH SCHEMABINDING
AS
BEGIN
RETURN @foo * 2
END
If I try to alter the function, SQL server shows the error
Cannot ALTER 'dbo.MyFunctionTest' it is being referenced by object 'TestTable'.
The only way for alter the function seem create a new one an alter the the table.
I've also tried to remove WITH SCHEMABINDING