microsoft / DacFx

DacFx, SqlPackage, and other SQL development libraries enable declarative database development and database portability across SQL versions and environments. Share feedback here on dacpacs, bacpacs, and SQL projects.
https://aka.ms/sqlpackage-ref
MIT License
362 stars 21 forks source link

Incorrect deployment plan order generated when a table valued function with schema binding is dependent on Temporal table #456

Open sejagada opened 5 months ago

sejagada commented 5 months ago
  1. Steps to Reproduce using WideWorldImporters Database:

    i. Install SQL Server 2022 & import WideWorldImporters database. ii. Right click on 'Application.Cities' -> Encrypt columns -> Select City Name -> New Encryption key -> Go to Summary & finish. Encryption fails with the below error.

    image (4)
  2. Steps to Reproduce by creating tables i. Install SQL Server 2022 & connect to it using SSMS. ii. Create a new database & create a temporal table as below:

       CREATE TABLE Department
        (
            DeptID INT NOT NULL PRIMARY KEY CLUSTERED,
            DeptName VARCHAR(50) NOT NULL,
            ManagerID INT NULL,
            ParentDeptID INT NULL,
            ValidFrom DATETIME2 GENERATED ALWAYS AS ROW START NOT NULL,
            ValidTo DATETIME2 GENERATED ALWAYS AS ROW END NOT NULL,
            PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo)
        )
        WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.DepartmentHistory));

    iii. Create a table-valued function with schema binding as below:

    CREATE FUNCTION Test(@ManagerID int)  
        RETURNS TABLE  
        WITH SCHEMABINDING
        AS  
        RETURN  
            SELECT ParentDeptID  
            FROM dbo.Department  
            WHERE ManagerID > @ManagerID

    iv. Right click on the table -> Encrypt columns -> Select DeptName -> New Encryption key -> Go to Summary & finish. Encryption fails with the same error as above.

DetermineCustomerAccess is a table value function with schema binding which depends on the temporal table Application.Cities. During the deployment, drop system-versioning step is being executed before schema unbinding step due to which the exception is thrown.