How to use ObjectProperty to locate problems in tables

Comments 0

Share to social media

There are plenty of very useful object properties that can help us to find problems in our databases. We can use object properties to find tables without primary key, tables without clustered index and much more information.

Object properties simplifies our queries, without them we would need to do much more complex queries over DMV’s to find the same information.

For example, to find if the table has clustered index, primary key, timestamp and identity, we can use the following query:

We can filter the information to get only tables that has some problems, like tables without primary keys or without clustered index:

We can create even a better solution with a table valued function that we can re-use:

We can use these queries together a DDL trigger to disallow the creation of tables without primary key. Let’s see how this trigger will work:

You can see a list with all the properties at https://msdn.microsoft.com/pt-br/library/ms176105.aspx

Load comments

About the author

Dennes Torres

See Profile

Dennes Torres is a Data Platform MVP and Software Architect living in Malta who loves SQL Server and software development and has more than 20 years of experience. Dennes can improve Data Platform Architectures and transform data in knowledge. He moved to Malta after more than 10 years leading devSQL PASS Chapter in Rio de Janeiro and now is a member of the leadership team of MMDPUG PASS Chapter in Malta organizing meetings, events, and webcasts about SQL Server. He is an MCT, MCSE in Data Platforms and BI, with more titles in software development. You can get in touch on his blog https://dennestorres.com or at his work https://dtowersoftware.com