For reporting purposes, I need to be able to query dependencies between views and underlying tables at column level (via sys.sql_expression_dependencies
).
One way to get SQL Server to store referenced columns is to use schemabound views. As some of my users will create views too, I would like to enforce those. As far as I've seen it isn't possible to allow only views with schemabinding to be created within a SQL Server database though (although this seems a legit requirement to me).
Are there other ways to force SQL Server to keep track of which columns are being referenced by which views? Or is there a hidden way to enforce schemabound views in SQL Server?
Best Answer
You could use a DDL trigger for this. Unfortunately
SCHEMABINDING
is not an attribute in theEVENTDATA
structure, so you have to construct the object name and check a property using that: