Skip to content

Instantly share code, notes, and snippets.

@cocowalla
Created February 5, 2021 09:08
Show Gist options
  • Save cocowalla/d1e8f82aa1cfe17caf7e814e1bbec448 to your computer and use it in GitHub Desktop.
Save cocowalla/d1e8f82aa1cfe17caf7e814e1bbec448 to your computer and use it in GitHub Desktop.
Conditional SQL Server Data Classification
DECLARE @compatibility_level TINYINT = 0;
SELECT @compatibility_level = compatibility_level FROM sys.databases WHERE name = 'MyDatabase';
PRINT CONCAT('Database compatibility level is: ', @compatibility_level);
IF @compatibility_level < 150
BEGIN
RAISERROR('Data Classification will not be performed, as database compatibility level %d is not high enough', 10, 1, @compatibility_level);
SET NOEXEC ON;
END;
GO
-- This will only be executed if database compatibility is >= 150
ADD SENSITIVITY CLASSIFICATION TO
MyTable.Forename,
MyTable.Surname
WITH (LABEL='Confidential - GDPR', INFORMATION_TYPE='Name', RANK=MEDIUM);
SET NOEXEC OFF;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment