Row-Level Security (RLS)
Row-Level Security (RLS) is a SQL statement in the Administration category. PostgreSQL: row-level security restricts which rows a user can see or modify based on a policy. The syntax is CREATE POLICY policy_name ON table_name FOR SELECT USING (condition);. It returns rLS policy. A typical example: CREATE TABLE orders (id INT, customer TEXT, amount DECIMAL); -- Enable RLS: ALTER TABLE orders ENABLE ROW LEVEL SECURITY; -- Create policies: CREATE POLICY customer_policy ON orders FOR ALL USING (customer = current_user); -- Users can only see their own orders CREATE POLICY manager_policy ON orders FOR SELECT USING (EXISTS (SELECT 1 FROM managers WHERE username = current_user)); -- Managers can see all orders -- SQL Server: row-level security with… A close relative is CREATE USER, which creates a new database user account. A close relative is GRANT, which grants specific privileges (SELECT, INSERT, UPDATE, DELETE, ALL) to a user on a database/table.