Working with database views for reporting
Summarize
Summary of Working with database views for reporting
Database views in ServiceNow define table joins specifically for reporting, enabling users to combine data from multiple tables (such as Incident, Metric Definition, and Metric Instance) into a single reportable source. These views simplify complex reporting needs by aggregating data without creating new custom tables and are available through plugins like Database View and Database Views for Service Management.
Show less
Key Features
- Reporting Source: Any user with report creation permissions can use database views as a data source.
- Access Control: ACLs on database views override underlying table ACLs if present; otherwise, table ACLs apply. Field-level ACLs on underlying tables are evaluated unless overridden by specific system properties.
- Performance Considerations: Performance impact increases with the number of tables and records included. Optimizing ‘where’ clauses using indexed fields improves efficiency.
- No Licensing Impact: Database views are not treated as custom tables and do not affect licensing.
- Limitations:
- Cannot be created on tables involved in table rotation.
- Data in database views is read-only.
- Database views cannot be used as data preservers in clone requests.
- Tables or views referenced across application scopes must follow scope extension rules for sysmetadata.
- Enhanced Reporting: Function fields can be added to database views to display computed results.
- Query Logic: ServiceNow processes conjunctions (AND) before disjunctions (OR) in queries involving database views.
- Reserved Words: Using MySQL reserved words in database views may cause performance issues and should be avoided.
Practical Application for ServiceNow Customers
ServiceNow customers can leverage database views to efficiently generate complex reports combining multiple data sources without needing custom tables or additional licensing. Proper understanding of ACL precedence ensures secure data access. Customers should optimize database views by focusing on indexed fields within ‘where’ clauses for performance and recognize that data from these views is read-only. Additionally, customers can extend reporting capabilities by including function fields and should be aware of limitations related to table rotation and cloning processes.
A database view defines table joins for reporting purposes.
For example, a database view can join the Incident table to the Metric Definition and Metric Instance tables. This view can be used to report on incident metrics and may include fields from any of these three tables.
Several useful database views are installed with the Database View plugin and the Database Views for Service Management plugin. These database views cover most metric reporting needs and greatly reduce the need to define new ones.
- If ACLs exist on the database view itself, those ACLs are evaluated and take precedence.
- If no database view ACLs exist, the system honors ACLs from the underlying tables.
- The accumulated impact on performance grows as the number of tables that are included in the view and the number of records that those tables contain increases. To maximize the performance of the database view, ensure that the ‘where’ clauses that are defined in the database view are based on indexed fields.
- A database view is not treated like a custom table, so there is no licensing impact.
- Database view tables are not included in FTP exports.
- Database views evaluate the ACLs of the parent table of a table included in the database view.
Limitations
- Database views cannot be created on tables that participate in table rotation.
- It is not possible to edit data in the database view output.
- Database view tables cannot be added as a data preserver in clone requests.
- You can reference a table or database view from a different application scope in a Table Name field. However, if the field belongs to a table that extends sys_metadata, the table or database view must belong to the same application scope as that table.
ACLs and database views
You don't need to create ACLs on fields in the view. If field-level ACLs exist, the system evaluates them.
To require that read ACLs be added to the database views, set the glide.security.expander.view.legacy property to true. On upgraded instances, add this system property and set it to true.
When glide.security.expander.view.legacy is true, underlying table ACLs are ignored. When the property is false (the default), the underlying table ACLs are used if there are no database view ACLs.
You can still create additional ACLs on the database views. These ACLs are evaluated last and are always honored.
Database view reserved words
Using the terms may cause unintended or undesirable performance. For more information, see the MySQL reserved words document.