Tenant Scoping
functionalConfigure the multi-tenant missing-filter guard: whether it runs, the tenant column, and the tenants table.
Configure SQLly's multi-tenant missing-filter guard for the current database. Four modes: Off (the default, nothing tenant-related is shown), Allowed (recognize tenant filters, never nag), Warn (a tenant-scoped table queried without its tenant predicate gets a validation warning), and Required (that omission becomes a blocking error and Run refuses). It is how you teach SQLly what "forgot the tenant filter" means for your schema.
Leave the tenant column blank and the guard uses the usual conventions -
TenantId, AccountId, OrganizationId,
OrgId and their underscored forms - or name your own column to narrow
detection. Optionally point it at the tenants table itself, with its id and display-name
columns. Changes save on every keystroke and apply to the next validation; the settings
live per server-and-database in a plain local file, like the rest of your SQLly
configuration.


Setting it up for a SaaS database
- Right-click the database and choose Tools › Tenant Scoping..., or run Tenant Scoping from the command palette while connected to it. The title shows the server and database being configured.
- Pick a mode. A one-line description under the buttons explains what the selected mode does.
- If your tenant column is not one of the conventional names - say it is
customer_id- type it in Tenant column. Once you name a column, only that column marks a table as tenant-scoped. - Optionally fill in Tenant table. Its Tenant id column and Tenant display-name column fields appear once a table is named.
- Close the dialog. There is no Save button; every change is already stored.
What the guard checks
A table counts as tenant-scoped when it has the tenant column. A statement
that reads, updates, or deletes from it must mention that column in a WHERE or
JOIN ... ON condition:
SELECT total FROM dbo.orders; -- flagged SELECT total FROM dbo.orders WHERE tenant_id = 7; -- fine SELECT o.total FROM dbo.orders o JOIN dbo.users u ON o.tenant_id = u.tenant_id; -- fine
The first statement gets a validation diagnostic in the editor, with a message such as `dbo.orders` is tenant-scoped by `tenant_id`, but the statement has no `tenant_id` filter in WHERE or JOIN ON.
- INSERT is exempt - the new rows carry their own tenant value.
- The tenant registry is exempt - a table whose primary key is the
tenant column, such as
tenants(tenant_id, name), is the list of tenants, not tenant data. - The check looks for the column in a condition; it does not judge the value you compare it to.
The four modes
| Mode | Effect |
|---|---|
| Off | The default for every database. The guard is disabled and nothing tenant-related is shown. The fields are hidden, and Off stores no column or table settings, so closing the dialog in Off discards them. |
| Allowed | No warnings or errors about missing tenant filters. Your column and table settings are kept. |
| Warn | A missing filter is a validation warning; Run still works. |
| Required | A missing filter is a validation error. Pressing Run refuses the batch and puts the message in the status bar, including when running against several targets at once. |
Where it is stored
Settings are keyed by server and database name, ignoring case, and saved as JSON in
tenant-scoping.json in SQLly's application data folder (on macOS,
~/Library/Application Support/SQLLY). A database you never configure is in
Off mode. The browser preview keeps the settings only for the current session.
Upgrading from an earlier version? The first time the new version starts, it clears every tenant-scoping setting saved before, once - including databases you had set to Warn or Required. If you want the guard on a database, open Tenant Scoping and switch it on again.
The guard needs the table's columns from the loaded schema model to know a table is tenant-scoped. Tables the model does not know about are not checked.