Module 18 · Lesson 10 of 10Detailed study · about 65 min

Enterprise Snowflake governance capstone: protect, audit and repair sales data

Build a governed customer and sales platform at Maple Market. Prove masking, regional access, lineage, quality failures and safe recovery.

Before you beginSet up the Maple Market governance lab

1. Agree on the business rules and success criteria

Maple Market needs sales totals by region and restricted contact data for support. Finance supplies an approved seven-order control of 650 in one currency. Contact names, email, phone, employee salaries and credit limits require review. Map each rule to an owner and a success or denial test before writing grants.

Use a non-trial Enterprise or higher scratch account for the full capstone, plus approved pre-existing users, one existing warehouse and the builder role. A second authorized operator can run the auditor steps. All outputs are expected or illustrative. You can follow the evidence without a Snowflake account. Start with unused lab identifiers. If you completed earlier lessons in this database, reuse only checkpoints whose state you verify. Do not rerun CREATE against existing objects or repeat repair on a different batch.

Approve the access and release contract
ActorPermitDeny or hold
SupportFull contact through CUSTOMER_CONTACTNo direct credit-limit or employee table read
AnalystDomain on a verified contact addressNo full address
India / Europe / USAssigned regional sales, with email hiddenSales outside that entitlement
Global reportingAll sales regionsUnmasked buyer email
RestrictedMasked contact view and zero SALES rowsEmployee and quarantine tables
Pipeline ownerWrite the protected sales target after a passing gatePublish a batch with unresolved rejects or wrong control totals
Enterprise governance workflow Access rules and release checks each have their own evidence.
  1. Customer, employee and sales sourcesClassify sources to Data inventory
  2. Data inventoryApply reviewed controls to Serving controls
  3. Customer, employee and sales sourcesCheck the incoming delivery to Batch validation
  4. Batch validationRelease only after reconciliation to Governed reports
  5. Serving controlsEnforce policies in each session to Governed reports
  6. Governed reportsVerify use and change impact to Audit and lineage
Customer, employee and sales sources
Synthetic records and a source control total.
Data inventory
Steward reviews classifications and attaches tags.
Serving controls
Policy owner restricts rows and values.
Batch validation
Operator records failures and approves a correction.
Governed reports
Readers test their permitted rows and values.
Audit and lineage
Auditor records use and downstream impact.

2–3. Create private data and separate builder, reader and auditor roles

Roles and privileges must exist before the builder can create the sample tables. Follow the SQL in order. The owner controls only this lab. Keep the selected warehouse’s usage separate from table permissions. After seeding, verify 5 customers, 2 employees and 3 sales as M18_OWNER. The consumer grants are applied separately after the policies.

Create roles as USERADMIN

SQL · runnable example
USE ROLE USERADMIN;
CREATE ROLE M18_OWNER;
CREATE ROLE M18_SUPPORT;
CREATE ROLE M18_ANALYST;
CREATE ROLE M18_IN;
CREATE ROLE M18_EU;
CREATE ROLE M18_US;
CREATE ROLE M18_GLOBAL;
CREATE ROLE M18_RESTRICTED;
CREATE ROLE M18_AUDITOR;

GRANT ROLE M18_ANALYST TO ROLE M18_IN;
GRANT ROLE M18_ANALYST TO ROLE M18_EU;
GRANT ROLE M18_ANALYST TO ROLE M18_US;
GRANT ROLE M18_ANALYST TO ROLE M18_GLOBAL;

GRANT ROLE M18_OWNER TO ROLE SYSADMIN;
GRANT ROLE M18_SUPPORT TO ROLE SYSADMIN;
GRANT ROLE M18_IN TO ROLE SYSADMIN;
GRANT ROLE M18_EU TO ROLE SYSADMIN;
GRANT ROLE M18_US TO ROLE SYSADMIN;
GRANT ROLE M18_GLOBAL TO ROLE SYSADMIN;
GRANT ROLE M18_RESTRICTED TO ROLE SYSADMIN;
GRANT ROLE M18_AUDITOR TO ROLE SYSADMIN;

Assign existing users and warehouse usage as SECURITYADMIN

Fill in the placeholders before running. The assigned users execute the allow and deny tests with secondary roles off.

SQL · configuration template
USE ROLE SECURITYADMIN;
GRANT ROLE M18_OWNER TO USER <builder_user>;
GRANT ROLE M18_SUPPORT TO USER <support_user>;
GRANT ROLE M18_ANALYST TO USER <analyst_user>;
GRANT ROLE M18_IN TO USER <india_user>;
GRANT ROLE M18_EU TO USER <europe_user>;
GRANT ROLE M18_US TO USER <us_user>;
GRANT ROLE M18_GLOBAL TO USER <global_user>;
GRANT ROLE M18_RESTRICTED TO USER <restricted_user>;
GRANT ROLE M18_AUDITOR TO USER <auditor_user>;

GRANT USAGE ON WAREHOUSE <approved_lab_warehouse> TO ROLE M18_OWNER;
GRANT USAGE ON WAREHOUSE <approved_lab_warehouse> TO ROLE M18_SUPPORT;
GRANT USAGE ON WAREHOUSE <approved_lab_warehouse> TO ROLE M18_ANALYST;
GRANT USAGE ON WAREHOUSE <approved_lab_warehouse> TO ROLE M18_RESTRICTED;
GRANT USAGE ON WAREHOUSE <approved_lab_warehouse> TO ROLE M18_AUDITOR;

Create the lab database as SYSADMIN

Transfer ownership before adding access to the database.

SQL · runnable example
USE ROLE SYSADMIN;
CREATE DATABASE LS_M18_GOV_LAB;
GRANT OWNERSHIP ON DATABASE LS_M18_GOV_LAB TO ROLE M18_OWNER;

Load the three source tables as M18_OWNER

SQL · configuration template
USE ROLE M18_OWNER;
USE WAREHOUSE <approved_lab_warehouse>;
USE DATABASE LS_M18_GOV_LAB;
CREATE SCHEMA CORE;
CREATE SCHEMA GOV;
CREATE SCHEMA QUALITY;
USE SCHEMA CORE;

CREATE TABLE CUSTOMERS (
  CUSTOMER_ID NUMBER NOT NULL, FULL_NAME VARCHAR, EMAIL VARCHAR,
  PHONE VARCHAR, CREDIT_LIMIT NUMBER(10,2), CONTACT_VERIFIED BOOLEAN
);
INSERT INTO CUSTOMERS VALUES
  (101,'Asha Rao','asha@example.invalid','+1-202-555-0101',2500,TRUE),
  (102,'Luc Martin','luc@example.invalid','+1-202-555-0102',1800,FALSE),
  (103,'Riley Chen','riley@example.invalid','+1-202-555-0103',3000,TRUE),
  (104,'Meera Shah','meera@example.invalid','+1-202-555-0104',2000,TRUE),
  (105,'Eva Wolf','eva@example.invalid','+1-202-555-0105',2100,TRUE);

CREATE TABLE EMPLOYEES (EMPLOYEE_ID NUMBER, DEPARTMENT VARCHAR, SALARY NUMBER);
INSERT INTO EMPLOYEES VALUES (11,'Finance',95000),(12,'Sales',74000);

CREATE TABLE SALES (
  SALE_ID NUMBER NOT NULL, CUSTOMER_ID NUMBER NOT NULL,
  REGION VARCHAR NOT NULL, AMOUNT NUMBER(10,2) NOT NULL, BUYER_EMAIL VARCHAR
);
INSERT INTO SALES VALUES
  (701,101,'IN',100,'asha@example.invalid'),
  (702,102,'EU',200,'luc@example.invalid'),
  (703,103,'US',150,'riley@example.invalid');

SELECT (SELECT COUNT(*) FROM CUSTOMERS) AS CUSTOMERS,
       (SELECT COUNT(*) FROM EMPLOYEES) AS EMPLOYEES,
       (SELECT COUNT(*) FROM SALES) AS SALES;

4–5. Review classification and apply approved tags

In the authorized Enterprise lab the owner runs the manual scan with auto_tag false. Treat the returned categories as suggestions. Confirm name, email and phone purpose and mark salaries and credit limits as restricted according to the business contract. There is no guaranteed classifier result on these small fictional inputs.

Apply the allowed values, override inherited ownership where it differs, and verify the email inventory. The label records the privacy decision. The next step separately enforces query behavior.

Review classification privileges and profiles →

Inspect classification evidence

SQL · runnable example
USE ROLE M18_OWNER;
CALL SYSTEM$CLASSIFY('LS_M18_GOV_LAB.CORE.CUSTOMERS', {'auto_tag': false});

Create the owner and sensitivity tags

SQL · runnable example
USE ROLE M18_OWNER;
CREATE TAG LS_M18_GOV_LAB.GOV.DATA_OWNER
  ALLOWED_VALUES 'commerce', 'people', 'finance', 'operations';
CREATE TAG LS_M18_GOV_LAB.GOV.SENSITIVITY
  ALLOWED_VALUES 'public', 'internal', 'restricted';
GRANT APPLY ON TAG LS_M18_GOV_LAB.GOV.DATA_OWNER TO ROLE M18_OWNER;
GRANT APPLY ON TAG LS_M18_GOV_LAB.GOV.SENSITIVITY TO ROLE M18_OWNER;

ALTER DATABASE LS_M18_GOV_LAB
  SET TAG LS_M18_GOV_LAB.GOV.DATA_OWNER = 'operations';
ALTER SCHEMA LS_M18_GOV_LAB.CORE
  SET TAG LS_M18_GOV_LAB.GOV.DATA_OWNER = 'commerce';
ALTER TABLE LS_M18_GOV_LAB.CORE.EMPLOYEES
  SET TAG LS_M18_GOV_LAB.GOV.DATA_OWNER = 'people';
ALTER TABLE LS_M18_GOV_LAB.CORE.CUSTOMERS
  MODIFY COLUMN EMAIL SET TAG LS_M18_GOV_LAB.GOV.SENSITIVITY = 'restricted';

Apply the other approved sensitivity labels

SQL · runnable example
USE ROLE M18_OWNER;
ALTER TABLE LS_M18_GOV_LAB.CORE.CUSTOMERS MODIFY COLUMN FULL_NAME
  SET TAG LS_M18_GOV_LAB.GOV.SENSITIVITY = 'restricted';
ALTER TABLE LS_M18_GOV_LAB.CORE.CUSTOMERS MODIFY COLUMN PHONE
  SET TAG LS_M18_GOV_LAB.GOV.SENSITIVITY = 'restricted';
ALTER TABLE LS_M18_GOV_LAB.CORE.CUSTOMERS MODIFY COLUMN CREDIT_LIMIT
  SET TAG LS_M18_GOV_LAB.GOV.SENSITIVITY = 'restricted';
ALTER TABLE LS_M18_GOV_LAB.CORE.EMPLOYEES MODIFY COLUMN SALARY
  SET TAG LS_M18_GOV_LAB.GOV.SENSITIVITY = 'restricted';
ALTER TABLE LS_M18_GOV_LAB.CORE.SALES MODIFY COLUMN BUYER_EMAIL
  SET TAG LS_M18_GOV_LAB.GOV.SENSITIVITY = 'restricted';

Confirm inherited and direct bindings

The EMAIL row should include SENSITIVITY = restricted. DATA_OWNER = commerce comes from CORE.

SQL · runnable example
SELECT COLUMN_NAME, TAG_NAME, TAG_VALUE, APPLY_METHOD
FROM TABLE(LS_M18_GOV_LAB.INFORMATION_SCHEMA.TAG_REFERENCES_ALL_COLUMNS(
  'LS_M18_GOV_LAB.CORE.CUSTOMERS', 'TABLE'))
WHERE TAG_DATABASE = 'LS_M18_GOV_LAB'
  AND TAG_SCHEMA = 'GOV'
  AND COLUMN_NAME IN ('CUSTOMER_ID','EMAIL')
ORDER BY COLUMN_NAME, TAG_NAME;

6–7. Apply masking and bind the regional row policy

The owner installs the policies before granting consumers access. The EMAIL policy binds a value and a verified flag. The full policy hides other contact values. The SALES_REGION policy binds REGION and reads the private entitlement map. The global and builder roles are explicit exceptions to the row restriction. Customer credit limits and employee salaries stay behind object permissions in this lab.

Attach the masking policies

SQL · runnable example
USE ROLE M18_OWNER;
CREATE MASKING POLICY LS_M18_GOV_LAB.GOV.CONTACT_EMAIL
AS (VAL VARCHAR, VERIFIED BOOLEAN) RETURNS VARCHAR ->
  CASE
    WHEN VAL IS NULL THEN NULL
    WHEN IS_ROLE_IN_SESSION('M18_OWNER')
      OR IS_ROLE_IN_SESSION('M18_SUPPORT') THEN VAL
    WHEN IS_ROLE_IN_SESSION('M18_ANALYST') AND COALESCE(VERIFIED,FALSE)
      AND POSITION('@' IN VAL) > 1 THEN '***@' || SPLIT_PART(VAL,'@',2)
    ELSE 'REDACTED'
  END;

GRANT APPLY ON MASKING POLICY LS_M18_GOV_LAB.GOV.CONTACT_EMAIL TO ROLE M18_OWNER;
ALTER TABLE LS_M18_GOV_LAB.CORE.CUSTOMERS MODIFY COLUMN EMAIL
  SET MASKING POLICY LS_M18_GOV_LAB.GOV.CONTACT_EMAIL
  USING (EMAIL, CONTACT_VERIFIED);

CREATE MASKING POLICY LS_M18_GOV_LAB.GOV.FULL_CONTACT
AS (VAL VARCHAR) RETURNS VARCHAR ->
  CASE
    WHEN VAL IS NULL THEN NULL
    WHEN IS_ROLE_IN_SESSION('M18_OWNER')
      OR IS_ROLE_IN_SESSION('M18_SUPPORT') THEN VAL
    ELSE 'REDACTED'
  END;

GRANT APPLY ON MASKING POLICY LS_M18_GOV_LAB.GOV.FULL_CONTACT TO ROLE M18_OWNER;
ALTER TABLE LS_M18_GOV_LAB.CORE.CUSTOMERS MODIFY COLUMN FULL_NAME
  SET MASKING POLICY LS_M18_GOV_LAB.GOV.FULL_CONTACT;
ALTER TABLE LS_M18_GOV_LAB.CORE.CUSTOMERS MODIFY COLUMN PHONE
  SET MASKING POLICY LS_M18_GOV_LAB.GOV.FULL_CONTACT;
ALTER TABLE LS_M18_GOV_LAB.CORE.SALES MODIFY COLUMN BUYER_EMAIL
  SET MASKING POLICY LS_M18_GOV_LAB.GOV.FULL_CONTACT;

Attach the regional restriction

SQL · runnable example
USE ROLE M18_OWNER;
CREATE TABLE LS_M18_GOV_LAB.GOV.REGION_ENTITLEMENT (ROLE_NAME VARCHAR, REGION VARCHAR);
INSERT INTO LS_M18_GOV_LAB.GOV.REGION_ENTITLEMENT VALUES
  ('M18_IN','IN'),('M18_EU','EU'),('M18_US','US');

CREATE ROW ACCESS POLICY LS_M18_GOV_LAB.GOV.SALES_REGION
AS (REQUESTED_REGION VARCHAR) RETURNS BOOLEAN ->
  IS_ROLE_IN_SESSION('M18_OWNER')
  OR IS_ROLE_IN_SESSION('M18_GLOBAL')
  OR EXISTS (
    SELECT 1 FROM LS_M18_GOV_LAB.GOV.REGION_ENTITLEMENT E
    WHERE E.REGION = REQUESTED_REGION AND IS_ROLE_IN_SESSION(E.ROLE_NAME)
  );

GRANT APPLY ON ROW ACCESS POLICY LS_M18_GOV_LAB.GOV.SALES_REGION TO ROLE M18_OWNER;
ALTER TABLE LS_M18_GOV_LAB.CORE.SALES
  ADD ROW ACCESS POLICY LS_M18_GOV_LAB.GOV.SALES_REGION ON (REGION);

Publish only the permitted contact interface

SQL · runnable example
USE ROLE M18_OWNER;
GRANT USAGE ON DATABASE LS_M18_GOV_LAB TO ROLE M18_SUPPORT;
GRANT USAGE ON DATABASE LS_M18_GOV_LAB TO ROLE M18_ANALYST;
GRANT USAGE ON DATABASE LS_M18_GOV_LAB TO ROLE M18_RESTRICTED;
GRANT USAGE ON SCHEMA LS_M18_GOV_LAB.CORE TO ROLE M18_SUPPORT;
GRANT USAGE ON SCHEMA LS_M18_GOV_LAB.CORE TO ROLE M18_ANALYST;
GRANT USAGE ON SCHEMA LS_M18_GOV_LAB.CORE TO ROLE M18_RESTRICTED;

CREATE SECURE VIEW LS_M18_GOV_LAB.CORE.CUSTOMER_CONTACT AS
  SELECT CUSTOMER_ID, FULL_NAME, EMAIL, PHONE FROM LS_M18_GOV_LAB.CORE.CUSTOMERS;
GRANT SELECT ON VIEW LS_M18_GOV_LAB.CORE.CUSTOMER_CONTACT TO ROLE M18_SUPPORT;
GRANT SELECT ON VIEW LS_M18_GOV_LAB.CORE.CUSTOMER_CONTACT TO ROLE M18_ANALYST;
GRANT SELECT ON VIEW LS_M18_GOV_LAB.CORE.CUSTOMER_CONTACT TO ROLE M18_RESTRICTED;

Grant access to the already protected sales table

SQL · runnable example
USE ROLE M18_OWNER;
GRANT USAGE ON DATABASE LS_M18_GOV_LAB TO ROLE M18_ANALYST;
GRANT USAGE ON DATABASE LS_M18_GOV_LAB TO ROLE M18_RESTRICTED;
GRANT USAGE ON SCHEMA LS_M18_GOV_LAB.CORE TO ROLE M18_ANALYST;
GRANT USAGE ON SCHEMA LS_M18_GOV_LAB.CORE TO ROLE M18_RESTRICTED;
GRANT SELECT ON TABLE LS_M18_GOV_LAB.CORE.SALES TO ROLE M18_ANALYST;
GRANT SELECT ON TABLE LS_M18_GOV_LAB.CORE.SALES TO ROLE M18_RESTRICTED;

8. Run both allowed and denied access tests

Each approved reader selects its assigned test role and the existing lab warehouse. Disable secondary roles so an inherited or extra support grant cannot accidentally explain a passing read. The contact view returns the same customer IDs under all three roles. Sales roles get different sets of IDs. An empty result for the restricted role is a policy decision even with SELECT.

Verify contact access under Support, Analyst and Restricted

Expected same customer rows under three roles
Active roleCustomer 101 emailCustomer 102 email
M18_SUPPORTasha@example.invalidluc@example.invalid
M18_ANALYST***@example.invalidREDACTED
M18_RESTRICTEDREDACTEDREDACTED
SQL · runnable example
USE SECONDARY ROLES NONE;
SELECT CURRENT_ROLE(), IS_ROLE_IN_SESSION('M18_ANALYST') AS HAS_ANALYST;
SELECT CUSTOMER_ID, EMAIL
FROM LS_M18_GOV_LAB.CORE.CUSTOMER_CONTACT
WHERE CUSTOMER_ID IN (101,102)
ORDER BY CUSTOMER_ID;

Verify all regional accounts and global reporting

Expected sales before the quality repair
Active roleVisible sale IDsAmountsBUYER_EMAIL
M18_IN701100REDACTED
M18_EU702200REDACTED
M18_US703150REDACTED
M18_GLOBAL701, 702, 703100, 200, 150REDACTED on each row
M18_RESTRICTEDNoneNo rowsNo rows
SQL · runnable example
USE SECONDARY ROLES NONE;
SELECT CURRENT_ROLE(), IS_ROLE_IN_SESSION('M18_ANALYST') AS HAS_ANALYST;
SELECT SALE_ID, REGION, AMOUNT, BUYER_EMAIL
FROM LS_M18_GOV_LAB.CORE.SALES
ORDER BY SALE_ID;

Run two separate denial tests as the India user

Expect authorization errors for both statements. Also run the allowed sales query and check the expected ID. An error in the allowed query can mean missing warehouse or object privileges rather than a correctly restricted policy.

SQL · runnable example
SELECT SALARY FROM LS_M18_GOV_LAB.CORE.EMPLOYEES;
SELECT ROLE_NAME, REGION FROM LS_M18_GOV_LAB.GOV.REGION_ENTITLEMENT;

9–11. Introduce the damaged delivery, monitor it and prove the release is blocked

As M18_OWNER create the private input and record the original rejects. The validation view identifies five bad deliveries. The approved manifest still expects seven and 650. The result from the release query is FALSE. The unchanged serving result of three rows and 450 proves the gate did not publish.

An authorized account administrator separately grants the privilege to attach the metrics in the Enterprise lab. The owner creates the three associations as shown. On demand, the two count expectations both fail with value 1. Save the results. Do not wait for an alert before holding the batch. The independent gate protects the serving data.

Expected release checkpoints
StateDeliveriesValidRejectedValid revenueRelease?Served rows / revenue
Broken input835450FALSE3 / 450
Verified correction770650TRUE7 / 650 after MERGE

Use scheduled history and configure notifications if approved →

Load the incoming sales and independent totals

SQL · runnable example
USE ROLE M18_OWNER;
CREATE TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES (
  DELIVERY_ID NUMBER NOT NULL, SALE_ID NUMBER NOT NULL,
  CUSTOMER_ID NUMBER NOT NULL, REGION VARCHAR, AMOUNT NUMBER(10,2),
  LOADED_AT TIMESTAMP_LTZ NOT NULL
);
INSERT INTO LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
SELECT COLUMN1,COLUMN2,COLUMN3,COLUMN4,COLUMN5,CURRENT_TIMESTAMP()
FROM VALUES
  (1,701,101,'IN',100),(2,702,102,'EU',200),(3,703,103,'US',150),
  (4,704,104,'IN',NULL),(5,705,105,'EU',60),(6,705,105,'EU',60),
  (7,706,999,'US',40),(8,707,101,'IN',-10);

CREATE TABLE LS_M18_GOV_LAB.QUALITY.BATCH_CONTROL (
  EXPECTED_ORDERS NUMBER NOT NULL, EXPECTED_REVENUE NUMBER(10,2) NOT NULL
);
INSERT INTO LS_M18_GOV_LAB.QUALITY.BATCH_CONTROL VALUES (7,650);

CREATE TABLE LS_M18_GOV_LAB.QUALITY.SALES_REJECTS (
  ATTEMPT_ID NUMBER, DELIVERY_ID NUMBER, SALE_ID NUMBER,
  CUSTOMER_ID NUMBER, REGION VARCHAR, AMOUNT NUMBER(10,2), REASON VARCHAR
);

Find the failed rows

Expected input issues
DeliverySaleReason
4704MISSING_AMOUNT
5705DUPLICATE_SALE
6705DUPLICATE_SALE
7706UNKNOWN_CUSTOMER
8707INVALID_AMOUNT
SQL · runnable example
CREATE VIEW LS_M18_GOV_LAB.QUALITY.SALES_VALIDATION AS
WITH deliveries AS (
  SELECT I.*, COUNT(*) OVER (PARTITION BY SALE_ID) AS COPIES
  FROM LS_M18_GOV_LAB.QUALITY.INCOMING_SALES I
), known_customers AS (
  SELECT CUSTOMER_ID, COUNT(*) AS MATCHES
  FROM LS_M18_GOV_LAB.CORE.CUSTOMERS
  GROUP BY CUSTOMER_ID
)
SELECT D.DELIVERY_ID, D.SALE_ID, D.CUSTOMER_ID, D.REGION, D.AMOUNT,
  CASE
    WHEN D.AMOUNT IS NULL THEN 'MISSING_AMOUNT'
    WHEN D.COPIES > 1 THEN 'DUPLICATE_SALE'
    WHEN C.MATCHES IS NULL THEN 'UNKNOWN_CUSTOMER'
    WHEN C.MATCHES <> 1 THEN 'AMBIGUOUS_CUSTOMER'
    WHEN D.REGION IS NULL OR D.REGION NOT IN ('IN','EU','US') THEN 'INVALID_REGION'
    WHEN D.AMOUNT <= 0 THEN 'INVALID_AMOUNT'
    ELSE NULL
  END AS REASON
FROM deliveries D
LEFT JOIN known_customers C ON C.CUSTOMER_ID = D.CUSTOMER_ID;

SELECT DELIVERY_ID, SALE_ID, REASON
FROM LS_M18_GOV_LAB.QUALITY.SALES_VALIDATION
WHERE REASON IS NOT NULL ORDER BY DELIVERY_ID;

Record the failed delivery evidence

SQL · runnable example
-- Use attempt 1 for the first review. Preserve its evidence during repair.
MERGE INTO LS_M18_GOV_LAB.QUALITY.SALES_REJECTS R
USING (
  SELECT 1 AS ATTEMPT_ID, DELIVERY_ID, SALE_ID, CUSTOMER_ID, REGION, AMOUNT, REASON
  FROM LS_M18_GOV_LAB.QUALITY.SALES_VALIDATION WHERE REASON IS NOT NULL
) S ON R.ATTEMPT_ID = S.ATTEMPT_ID AND R.DELIVERY_ID = S.DELIVERY_ID
WHEN NOT MATCHED THEN INSERT
  (ATTEMPT_ID,DELIVERY_ID,SALE_ID,CUSTOMER_ID,REGION,AMOUNT,REASON)
  VALUES (S.ATTEMPT_ID,S.DELIVERY_ID,S.SALE_ID,S.CUSTOMER_ID,S.REGION,S.AMOUNT,S.REASON);

SELECT ATTEMPT_ID, DELIVERY_ID, SALE_ID, REASON
FROM LS_M18_GOV_LAB.QUALITY.SALES_REJECTS ORDER BY ATTEMPT_ID, DELIVERY_ID;

Set the independent release decision

SQL · runnable example
CREATE VIEW LS_M18_GOV_LAB.QUALITY.SALES_RELEASE_CHECK AS
WITH measured AS (
  SELECT COUNT(*) AS DELIVERIES,
         COUNT(CASE WHEN REASON IS NULL THEN 1 END) AS VALID_ORDERS,
         COUNT(CASE WHEN REASON IS NOT NULL THEN 1 END) AS REJECTED,
         COALESCE(SUM(CASE WHEN REASON IS NULL THEN AMOUNT END),0) AS VALID_REVENUE
  FROM LS_M18_GOV_LAB.QUALITY.SALES_VALIDATION
), manifest AS (
  SELECT COUNT(*) AS MANIFEST_ROWS,
         MAX(EXPECTED_ORDERS) AS EXPECTED_ORDERS,
         MAX(EXPECTED_REVENUE) AS EXPECTED_REVENUE
  FROM LS_M18_GOV_LAB.QUALITY.BATCH_CONTROL
)
SELECT M.*, C.EXPECTED_ORDERS, C.EXPECTED_REVENUE,
       C.MANIFEST_ROWS = 1 AND M.REJECTED = 0
         AND M.VALID_ORDERS = C.EXPECTED_ORDERS
         AND M.VALID_REVENUE = C.EXPECTED_REVENUE AS RELEASE_OK
FROM measured M CROSS JOIN manifest C;

SELECT * FROM LS_M18_GOV_LAB.QUALITY.SALES_RELEASE_CHECK;

Prove the failed batch cannot publish

SQL · runnable example
MERGE INTO LS_M18_GOV_LAB.CORE.SALES T
USING (
  SELECT V.SALE_ID, V.CUSTOMER_ID, V.REGION, V.AMOUNT, C.EMAIL AS BUYER_EMAIL
  FROM LS_M18_GOV_LAB.QUALITY.SALES_VALIDATION V
  JOIN LS_M18_GOV_LAB.CORE.CUSTOMERS C ON C.CUSTOMER_ID = V.CUSTOMER_ID
  CROSS JOIN LS_M18_GOV_LAB.QUALITY.SALES_RELEASE_CHECK R
  WHERE V.REASON IS NULL AND R.RELEASE_OK
) S ON T.SALE_ID = S.SALE_ID
WHEN MATCHED AND (
  T.CUSTOMER_ID IS DISTINCT FROM S.CUSTOMER_ID OR T.REGION IS DISTINCT FROM S.REGION
  OR T.AMOUNT IS DISTINCT FROM S.AMOUNT OR T.BUYER_EMAIL IS DISTINCT FROM S.BUYER_EMAIL
) THEN UPDATE SET CUSTOMER_ID = S.CUSTOMER_ID, REGION = S.REGION,
                  AMOUNT = S.AMOUNT, BUYER_EMAIL = S.BUYER_EMAIL
WHEN NOT MATCHED THEN INSERT (SALE_ID,CUSTOMER_ID,REGION,AMOUNT,BUYER_EMAIL)
  VALUES (S.SALE_ID,S.CUSTOMER_ID,S.REGION,S.AMOUNT,S.BUYER_EMAIL);

SELECT COUNT(*) AS ORDERS, SUM(AMOUNT) AS REVENUE
FROM LS_M18_GOV_LAB.CORE.SALES;

Grant the monitoring privilege as administrator

SQL · runnable example
USE ROLE ACCOUNTADMIN;
GRANT EXECUTE DATA METRIC FUNCTION ON ACCOUNT TO ROLE M18_OWNER;

Attach measurements as the lab owner

SQL · runnable example
USE ROLE M18_OWNER;
CREATE DATA METRIC FUNCTION LS_M18_GOV_LAB.QUALITY.COUNT_NONPOSITIVE(
  INPUT_ROWS TABLE (AMOUNT NUMBER)
) RETURNS NUMBER AS $$
  SELECT COUNT(*) FROM INPUT_ROWS WHERE AMOUNT <= 0
$$;

ALTER TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
  SET DATA_METRIC_SCHEDULE = '5 MINUTE';
ALTER TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
  ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.NULL_COUNT ON (AMOUNT)
    EXPECTATION MISSING_AMOUNT_ZERO (VALUE = 0);
ALTER TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
  ADD DATA METRIC FUNCTION LS_M18_GOV_LAB.QUALITY.COUNT_NONPOSITIVE ON (AMOUNT)
    EXPECTATION NONPOSITIVE_ZERO (VALUE = 0);
ALTER TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
  ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.FRESHNESS ON (LOADED_AT)
    EXPECTATION LOADED_WITHIN_30_MINUTES (VALUE >= 0 AND VALUE <= 1800);

Evaluate the failed expectations

Expected value checks before and after repair
ExpectationBroken valueBroken violated?Repaired valueRepaired violated?
MISSING_AMOUNT_ZERO1TRUE0FALSE
NONPOSITIVE_ZERO1TRUE0FALSE
SQL · runnable example
SELECT METRIC_NAME, EXPECTATION_NAME, VALUE, EXPECTATION_VIOLATED
FROM TABLE(SYSTEM$EVALUATE_DATA_QUALITY_EXPECTATIONS(
  REF_ENTITY_NAME => 'LS_M18_GOV_LAB.QUALITY.INCOMING_SALES'))
ORDER BY METRIC_NAME;

12–13. Audit the approved sensitive read and investigate downstream impact

Create the report as M18_OWNER while the data is still at the previous valid version. The SQL groups by REGION, with REVENUE computed from SALES.AMOUNT. Record the exact role and query ID during a Support contact read. History can arrive after you finish the data repair. Assign the lookup to the auditor and keep its time and object scope narrow.

Check the downstream report before changing an amount field or its meaning. Use a metadata-only role for the dependency lookup and the owner for GET_LINEAGE on the lab objects. In Snowsight select the AMOUNT column to find the downstream REVENUE field. A column rename requires review with downstream owners. This lab repairs source values and keeps the existing schema.

Interpret lineage, delays and failed access evidence →

Create the secure report as owner

SQL · runnable example
USE ROLE M18_OWNER;
CREATE SECURE VIEW LS_M18_GOV_LAB.CORE.SALES_BY_REGION AS
  SELECT REGION, SUM(AMOUNT) AS REVENUE, COUNT(*) AS SALES_COUNT
  FROM LS_M18_GOV_LAB.CORE.SALES
  GROUP BY REGION;

GRANT SELECT ON VIEW LS_M18_GOV_LAB.CORE.SALES_BY_REGION TO ROLE M18_ANALYST;
SELECT REGION, REVENUE, SALES_COUNT
FROM LS_M18_GOV_LAB.CORE.SALES_BY_REGION ORDER BY REGION;

Grant the approved metadata roles as ACCOUNTADMIN

SQL · runnable example
USE ROLE ACCOUNTADMIN;
GRANT DATABASE ROLE SNOWFLAKE.GOVERNANCE_VIEWER TO ROLE M18_AUDITOR;
GRANT DATABASE ROLE SNOWFLAKE.OBJECT_VIEWER TO ROLE M18_AUDITOR;

Record one approved Support query in a dedicated session

SQL · runnable example
USE ROLE M18_SUPPORT;
USE SECONDARY ROLES NONE;
ALTER SESSION SET QUERY_TAG = 'maple_m18_contact_review';
SELECT CUSTOMER_ID, EMAIL
FROM LS_M18_GOV_LAB.CORE.CUSTOMER_CONTACT
WHERE CUSTOMER_ID = 101;
ALTER SESSION UNSET QUERY_TAG;

Inspect the known access record after history arrives

SQL · runnable example
SELECT A.QUERY_ID, A.QUERY_START_TIME, A.USER_NAME, Q.ROLE_NAME,
       O.VALUE:objectName::VARCHAR AS BASE_OBJECT,
       C.VALUE:columnName::VARCHAR AS ACCESSED_COLUMN
FROM SNOWFLAKE.ACCOUNT_USAGE.ACCESS_HISTORY A
JOIN SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY Q ON Q.QUERY_ID = A.QUERY_ID,
LATERAL FLATTEN(INPUT => A.BASE_OBJECTS_ACCESSED) O,
LATERAL FLATTEN(INPUT => O.VALUE:columns) C
WHERE A.QUERY_START_TIME >= DATEADD('hour', -24, CURRENT_TIMESTAMP())
  AND Q.START_TIME >= DATEADD('hour', -24, CURRENT_TIMESTAMP())
  AND Q.QUERY_TAG = 'maple_m18_contact_review'
  AND O.VALUE:objectName::VARCHAR = 'LS_M18_GOV_LAB.CORE.CUSTOMERS'
  AND C.VALUE:columnName::VARCHAR = 'EMAIL'
ORDER BY A.QUERY_START_TIME DESC;

Check dependent objects as M18_AUDITOR

SQL · runnable example
SELECT REFERENCED_OBJECT_NAME AS SOURCE_OBJECT,
       REFERENCING_OBJECT_NAME AS DEPENDENT_OBJECT, DEPENDENCY_TYPE
FROM SNOWFLAKE.ACCOUNT_USAGE.OBJECT_DEPENDENCIES
WHERE REFERENCED_DATABASE = 'LS_M18_GOV_LAB'
  AND REFERENCED_SCHEMA = 'CORE'
  AND REFERENCED_OBJECT_NAME = 'SALES'
  AND REFERENCING_DATABASE = 'LS_M18_GOV_LAB';

Read the supported downstream evidence as M18_OWNER

SQL · runnable example
SELECT SOURCE_OBJECT_NAME, TARGET_OBJECT_NAME, DISTANCE
FROM TABLE(SNOWFLAKE.CORE.GET_LINEAGE(
  'LS_M18_GOV_LAB.CORE.SALES', 'TABLE', 'DOWNSTREAM', 1))
ORDER BY TARGET_OBJECT_NAME;

14–16. Repair the source, verify the report and assign owners

Finance approves the corrected manifest and the data operator applies the four source corrections. Read the gate and rerun the same publish statement. It inserts four new rows. The second run changes zero. The reconciliation should return no differences. Retest each region because a data fix is only complete when the same access controls still hold.

After the correction, India sees 701, 704 and 707 totaling 200. Europe sees 702 and 705 totaling 260. US sees 703 and 706 totaling 190. Global reporting sees 7 sales totaling 650. The email rule stays active. The input owner rechecks both count expectations at zero and waits for the next scheduled record if required by the runbook.

Agree who handles a quality alert, which failed batch and query IDs to record, and when to notify downstream owners. Maintain the access matrix, review role grants and confirm the next data arrival. In a real project, put incident references and SQL version IDs in the checklist instead of raw addresses.

Expected final report after repair
REGIONSALES_COUNTREVENUE
EU2260
IN3200
US2190

Apply the source-approved correction as owner

SQL · runnable example
-- Model an approved source correction in the disposable lab only.
BEGIN TRANSACTION;
UPDATE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES SET AMOUNT = 90
WHERE DELIVERY_ID = 4 AND SALE_ID = 704 AND AMOUNT IS NULL;
DELETE FROM LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
WHERE DELIVERY_ID = 6 AND SALE_ID = 705;
UPDATE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES SET CUSTOMER_ID = 103
WHERE DELIVERY_ID = 7 AND SALE_ID = 706 AND CUSTOMER_ID = 999;
UPDATE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES SET AMOUNT = 10
WHERE DELIVERY_ID = 8 AND SALE_ID = 707 AND AMOUNT = -10;
COMMIT;

SELECT * FROM LS_M18_GOV_LAB.QUALITY.SALES_RELEASE_CHECK;

Publish once, then retry against the unchanged snapshot

SQL · runnable example
MERGE INTO LS_M18_GOV_LAB.CORE.SALES T
USING (
  SELECT V.SALE_ID, V.CUSTOMER_ID, V.REGION, V.AMOUNT, C.EMAIL AS BUYER_EMAIL
  FROM LS_M18_GOV_LAB.QUALITY.SALES_VALIDATION V
  JOIN LS_M18_GOV_LAB.CORE.CUSTOMERS C ON C.CUSTOMER_ID = V.CUSTOMER_ID
  CROSS JOIN LS_M18_GOV_LAB.QUALITY.SALES_RELEASE_CHECK R
  WHERE V.REASON IS NULL AND R.RELEASE_OK
) S ON T.SALE_ID = S.SALE_ID
WHEN MATCHED AND (
  T.CUSTOMER_ID IS DISTINCT FROM S.CUSTOMER_ID OR T.REGION IS DISTINCT FROM S.REGION
  OR T.AMOUNT IS DISTINCT FROM S.AMOUNT OR T.BUYER_EMAIL IS DISTINCT FROM S.BUYER_EMAIL
) THEN UPDATE SET CUSTOMER_ID = S.CUSTOMER_ID, REGION = S.REGION,
                  AMOUNT = S.AMOUNT, BUYER_EMAIL = S.BUYER_EMAIL
WHEN NOT MATCHED THEN INSERT (SALE_ID,CUSTOMER_ID,REGION,AMOUNT,BUYER_EMAIL)
  VALUES (S.SALE_ID,S.CUSTOMER_ID,S.REGION,S.AMOUNT,S.BUYER_EMAIL);

SELECT COUNT(*) AS ORDERS, SUM(AMOUNT) AS REVENUE
FROM LS_M18_GOV_LAB.CORE.SALES;

Check the data from both directions

SQL · runnable example
WITH target AS (
  SELECT SALE_ID, COUNT(*) AS COPIES, MIN(CUSTOMER_ID) AS CUSTOMER_ID,
         MIN(REGION) AS REGION, MIN(AMOUNT) AS AMOUNT
  FROM LS_M18_GOV_LAB.CORE.SALES GROUP BY SALE_ID
)
SELECT COALESCE(T.SALE_ID, S.SALE_ID) AS SALE_ID,
       S.AMOUNT AS SOURCE_AMOUNT, T.AMOUNT AS TARGET_AMOUNT, T.COPIES
FROM LS_M18_GOV_LAB.QUALITY.SALES_VALIDATION S
FULL OUTER JOIN target T ON T.SALE_ID = S.SALE_ID
WHERE T.SALE_ID IS NULL OR S.SALE_ID IS NULL OR S.REASON IS NOT NULL
   OR T.COPIES <> 1 OR T.CUSTOMER_ID IS DISTINCT FROM S.CUSTOMER_ID
   OR T.REGION IS DISTINCT FROM S.REGION OR T.AMOUNT IS DISTINCT FROM S.AMOUNT
ORDER BY SALE_ID;

Check the report under global and regional roles

Switch to the reader’s assigned role and warehouse and disable secondary roles, as in the earlier access checks. Verify the global totals and each regional subset.

SQL · runnable example
SELECT REGION, SALES_COUNT, REVENUE
FROM LS_M18_GOV_LAB.CORE.SALES_BY_REGION ORDER BY REGION;

Recheck active bindings as the owner

SQL · runnable example
SELECT POLICY_KIND, POLICY_NAME, REF_COLUMN_NAME, POLICY_STATUS
FROM TABLE(LS_M18_GOV_LAB.INFORMATION_SCHEMA.POLICY_REFERENCES(
  REF_ENTITY_NAME => 'LS_M18_GOV_LAB.CORE.SALES', REF_ENTITY_DOMAIN => 'TABLE'))
ORDER BY POLICY_KIND, REF_COLUMN_NAME;

Check both current and scheduled evidence as the owner

SQL · runnable example
SELECT METRIC_NAME, EXPECTATION_NAME, VALUE, EXPECTATION_VIOLATED
FROM TABLE(SYSTEM$EVALUATE_DATA_QUALITY_EXPECTATIONS(
  REF_ENTITY_NAME => 'LS_M18_GOV_LAB.QUALITY.INCOMING_SALES'))
ORDER BY METRIC_NAME;

Confirm the next scheduled measurement

SQL · runnable example
SELECT MEASUREMENT_TIME, METRIC_NAME, VALUE, EXPECTATION_VIOLATED
FROM TABLE(SNOWFLAKE.LOCAL.DATA_QUALITY_MONITORING_EXPECTATION_STATUS(
  REF_ENTITY_NAME => 'LS_M18_GOV_LAB.QUALITY.INCOMING_SALES',
  REF_ENTITY_DOMAIN => 'TABLE'))
WHERE MEASUREMENT_TIME >= DATEADD('hour', -2, CURRENT_TIMESTAMP())
ORDER BY MEASUREMENT_TIME DESC, METRIC_NAME;

Clean up the isolated lab after recording evidence

Keep the query IDs, approved role labels and counts according to the lab’s evidence rules. If you used optional classification or notifications, unset the profile and disable its notifications before cleanup. Stop the scheduled metrics if they were added. Check SHOW DATABASES LIKE 'LS_M18_GOV_LAB' and confirm the unique lab name and owner before dropping it.

M18_OWNER can drop the closed lab database. The administrator then drops only the nine lab roles. Dropping the roles removes their role and warehouse grants while leaving the approved warehouse and users in place. Verify an old reader cannot use the removed role and SHOW DATABASES LIKE no longer lists the active lab. Dropped objects can still be subject to retention rules.

Stop the scheduling and detach the lab DMFs if installed

SQL · runnable example
ALTER TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES SET DATA_METRIC_SCHEDULE = '';
ALTER TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
  DROP DATA METRIC FUNCTION SNOWFLAKE.CORE.NULL_COUNT ON (AMOUNT);
ALTER TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
  DROP DATA METRIC FUNCTION LS_M18_GOV_LAB.QUALITY.COUNT_NONPOSITIVE ON (AMOUNT);
ALTER TABLE LS_M18_GOV_LAB.QUALITY.INCOMING_SALES
  DROP DATA METRIC FUNCTION SNOWFLAKE.CORE.FRESHNESS ON (LOADED_AT);
DROP FUNCTION LS_M18_GOV_LAB.QUALITY.COUNT_NONPOSITIVE(TABLE(NUMBER));

Drop the verified lab database as owner

SQL · runnable example
USE ROLE M18_OWNER;
DROP DATABASE LS_M18_GOV_LAB;
SHOW DATABASES LIKE 'LS_M18_GOV_LAB';

Retire only the approved lab roles

SQL · runnable example
USE ROLE SECURITYADMIN;
DROP ROLE M18_IN;
DROP ROLE M18_EU;
DROP ROLE M18_US;
DROP ROLE M18_GLOBAL;
DROP ROLE M18_ANALYST;
DROP ROLE M18_SUPPORT;
DROP ROLE M18_RESTRICTED;
DROP ROLE M18_AUDITOR;
DROP ROLE M18_OWNER;

Interview practice

Explain the decision and the evidence you would use to test it.

What keeps the sales email private?

The row policy restricts which orders a role sees. The masking policy then substitutes the buyer email on those rows. I verify both under actual consumer roles and check that they cannot read the private tables.

How do you prove the bad batch was contained?

I record the five rejects and the FALSE release decision, then run the same MERGE and confirm no rows changed. After the approved repair I prove 7 orders and 650, reconcile each key and retry once to verify no duplicate writes.

How would you investigate a suspected exposure during the incident?

I save the query ID and compare the login, role, object and column with the policy bindings and allowed use. Access History could show a masked column was referenced. I would verify what the role could actually receive before concluding that a raw value was exposed.

Words used in this lesson
Access matrix
The allowed and denied access expected for each role.
Release evidence
Checks showing the corrected source matches the result.
Audit trail
Query IDs and incident references that explain what happened.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 1

Enterprise Snowflake governance capstone: protect, audit and repair sales data

Customer, employee and sales sources
Data inventory
Serving controls
Batch validation
Governed reports
Audit and lineage

Enterprise governance workflow

Access rules and release checks each have their own evidence.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Enterprise governance workflow

    Access rules and release checks each have their own evidence.

    Customer, employee and sales sources → Data inventory → Serving controls → Batch validation → Governed reports → Audit and lineage

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

All records are fictional. Outputs are expected or simulated. Live practice needs an authorized scratch account, test roles, an approved warehouse and the editions listed in the lesson.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Which result demonstrates both correct release and regional governance?

Try it yourself

Write a handoff that names the failed source, the amount of trusted sales and the tests you need before reopening the report.

Compare your reasoning

Record the bad delivery and five held rows, confirm the previous 450 stayed available, obtain source-approved corrections and reproduce the 650 global result plus the regional and masked reads.

Connect this lesson to the learning path

Official sources and curriculum

Module 18 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab