-
Notifications
You must be signed in to change notification settings - Fork 25
Description
- SqlPackage.exe version: 162.0.52
- SqlServer version: Microsoft SQL Server 2019 (RTM-CU19) (KB5023049) - 15.0.4298.1 (X64)
- Target database compatibility level: 150
Steps to Reproduce:
- Create an in-memory sqlproj, add a table with a couple of columns
- Create function with options
WITH NATIVE_COMPILATION, SCHEMABINDINGwhich selects from this table - Deploy this project
- Add a column to the table
- Try to deploy modified project and get invalid syntax error
SqlPackage tries to behave like this is not memory optimized project and to be able to alter the table SqlPackage temporarily removes SCHEMABINDING option from dependent function. But natively-compiled functions must have SCHEMABINDING option, otherwise syntax is invalid.
Example of generated deployment script part (obfuscated):
GO
PRINT N'Removing schema binding from [my].[fn]...';
GO
ALTER FUNCTION my.fn
(@bar INT NULL)
RETURNS TABLE
WITH NATIVE_COMPILATION ---<<< this is illegal, it MUST have SCHEMABINDING option
AS
RETURN
SELECT t.id
FROM dbo.altered_table AS t
WHERE t.foo = @bar
GO
PRINT N'Altering Table dbo.altered_table...';
GO
ALTER TABLE dbo.altered_table
ADD new_col INT NULL;
GO
PRINT N'Adding schema binding to my.fn...';
GO
ALTER FUNCTION my.fn
(@bar INT NULL)
RETURNS TABLE
WITH NATIVE_COMPILATION, SCHEMABINDING
AS
RETURN
SELECT t.id
FROM dbo.altered_table AS t
WHERE t.foo = @bar
GO
So there are two things
- to add a column you don't need to unbind dependent objects, you can just do
ALTER TABLE ADD - removing
SCHEMABINDINGfromNATIVE_COMPILATIONobjects is illegal, you need some other approach; like regenerating with fake body or something
Did this occur in prior versions? If not - which version(s) did it work in?
No version found where it works.
How we workaround this issue: we add column with ALTER TABLE ... ADD ... before deployment via sqlpackage.
ps
I don't really understand where I should report this issue. Here is a feedback on azure.com , here is a thread on stackoverflow, both are dead ends.
(DacFx/SqlPackage/SSMS/Azure Data Studio)