1

SQL Server’s Indexed Views provide a performant way to implement certain classes of database-scoped constraints - such as ensuring a value is unique over multiple tables - or other non-key, cross-table value constraints.

As far as I understand it: provided you can reduce your desired constraint to a single SELECT query using some combination of INNER JOIN, CROSS JOIN, and/or COUNT_BIG/SUM such that invalid data causes duplicate output rows then using an indexed-view is doable.

…but how can I know (or ideally: prove) that some proposed constraint can be implemented this way? And how can I know that some other kind of constraint is impossible to implement?

Another consideration is that the limitation of only having INNER JOIN and CROSS JOIN becomes less of a restriction with the help of utility-tables containing data-ranges (either manually maintained or using GENERATE_SERIES) - this enables other classes of constraints to be implemented - but I struggle to conceptualise those classes (do they have names?)

Dai
  • 632
  • 4
  • 20

0 Answers0