RLS Samples

Getting started demos

RLS-Hospital-Builtin-Demo.sql
This demo shows how to use RLS to control access to rows based on SQL Server's built-in security system (users and roles). Use this approach when each user has their own SQL login.

RLS-Projects-MidTier-Demo.sql
This demo shows how to use RLS for middle-tier applications, where all database queries are done via a shared SQL login or service account. This is a common pattern for multi-tenant web apps.

Advanced scenarios

RLS-Performance-Common-Patterns.sql
This demo demonstrates three common patterns for implementing RLS predicates. In addition, this demo shows how RLS has performance comparable to what you'd get with view-based workarounds for row-level filtering.
Details:
Row-Level Security: Performance and common patterns

RLS-Query-Store.sql
This demo shows how to optimize the performance of RLS predicates by A/B testing different configurations, and using the Query Store to measure the performance impact.
Details:
Optimizing RLS performance with the Query Store

RLS-Blocking-Inserts.sqlNOTE: This workaround is now obsolete due to the introduction of block predicates. We've left this here for reference, but you should really use
block predicates instead. This demo shows how to implement "insert-blocking" functionality using check constraints, as an additional safeguard against mistakes in your app code.
Details:
Row-Level Security: Blocking unauthorized INSERTs