I'm using Row-Level Security on a temporal table in my SQL Server database. In order to comply with GDPR, I need to be able to not only delete this data in this table that is from the present, but also its _History table (temporal table).
Before RLS, I used to do:
ALTER TABLE [dbo].[Table] SET (SYSTEM_VERSIONING = OFF);
DELETE FROM [dbo].[Table_History] WHERE UserID=@userID;
ALTER TABLE [dbo].[Table] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[Table_History]));
But now, this generates the error:
Cannot ALTER 'Table' because it is being referenced by object 'fn_Table_Predicate'.
What's the proper way to enable & disable system versioning with RLS enabled?