Business rules & audit

The database stays in charge.

People edit the table, but the table's owner writes the rules, the server records who changed what, and the database has the final word on every row.

The Business Rules section of a dataset's design, with SQL rules set to run on insert, update and delete.
Why it matters

Governance that comes from the save itself

An audit trail people have to remember to keep is not an audit trail.

Audit columns are configured once per dataset: a user name, a user id or a UTC date and time, written on insert, on update or on both. The server fills them in on every save, and ignores whatever the browser sends for them.

Business rules are SQL statements the owner attaches to the dataset. A rule can run for every changed row, with the row's current and previous values, or once after the whole save. And when the database itself refuses a row, the person saving sees that row's reason, while the rest of the save goes through.

Walkthrough

Rules and audit, step by step

Screens from the product.

Step 1

Run SQL when rows change

Each business rule is a SQL statement with check boxes for when it runs: on delete, on insert, on update, and per record. Rules run in priority order, and the keyword list shows the values a rule can use.

  • @CURRENT$column$ and @PREVIOUS$column$ in per-record rules
  • Rules that are not per record run once, after the last batch
  • @USERPRINCIPALNAME and @USEROBJECTID in any rule
The Business Rules section: a per-record rule writing a history row on update, and a rule refreshing totals once per save.
Step 2

Audit columns the browser cannot forge

A column handled as Audit records the signed-in user's name or id, or the UTC date and time, on insert, on update or both. It is read-only in the grid, and the server writes it.

  • User Name, User Id or Date and Time (UTC)
  • Insert only, Update only, or Insert and Update
  • Never taken from the browser
The dataset's columns with Modified by and Modified at handled as audit columns, applied on insert and update.
Step 3

See which row the database rejected

When the database refuses a row, for example because it breaks a CHECK constraint, the grid adds an Error column with the database's own message on that row. The row keeps its pending change, and the other rows are saved.

  • The reason, on the row it belongs to
  • A message saying how many rows were saved
  • Fix the row and save again
A partly rejected save: SQL Server's CHECK constraint message in the Error column of the refused row, whose new target is still pending, beside the row that was saved.
Step 4

Rows per user

The dataset's Filter SQL decides which rows are loaded, and it can use the signed-in user's identity: WHERE Owner = @USERPRINCIPALNAME gives everyone their own rows from one shared table. The access report marks such a dataset as Rows filtered per user.

  • @USERPRINCIPALNAME and @USEROBJECTID
  • :USERPRINCIPALNAME and :USEROBJECTID on Databricks
  • Combined with folder access for two layers of control
Highlights

Controls that hold up in an audit

Because they are enforced where people cannot reach them.

A history table in one rule

A per-record rule on update can insert the previous and the new value of every changed row into a history table.

Constraints still apply

Keys, CHECK constraints and triggers in the database apply to every save, and their messages reach the person saving.

Entra SSO end to end

With Entra SSO, each statement runs as the person saving, so database permissions and auditing see them too.

Related

Keep exploring

Features that rules and audit work with.

See a rule run

Save anything in the playground and it lists the statements sent, the per-record history rule and the rule run once after the save.