Find All Custom SQL Objects In Database

Microsoft SQL ServerQuite a long time ago I started using a particular naming convention when creating SQL objects such as tables, triggers, or views. The plan was so that they were easy to find in the database.

With some clients who have objects with this naming convention looking to do upgrades I’ve taken the next step and created some SQL queries to select all of these objects (which was always the next step).

The naming convention I adopted is in the following format:

  • type
  • organisation who created
  • client
  • name (which will be omitted if the object is a generic one which might be given to multiple clients)

So, a custom table, created by azurecurve for Fabrikam, Inc. to store a Sales Order/Assembly cross reference would be called ut_AZRCRV_FAB_SalesOrderAssemblyXref.

The type prefix varies by object type, but always starts with a u for user. The types I use are:

  • ut for tables
  • uv for views
  • uf for functions
  • usp for stored procedures
  • utr for triggers

The following view (following my naming convention above lacks a client as it is generic) selects all custom objects in the database created by AZRCRV:

Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
SELECT,'' AS 'table name', o.type_desc, o.modify_date FROM sys.objects AS o WHERE LIKE 'u__AZRCRV_%'
SELECT,, o.type_desc, o.modify_date FROM sys.indexes AS i INNER JOIN sys.objects AS o ON o.object_id = i.object_id WHERE LIKE 'u%_AZRCRV_%'
SELECT,, t.type_desc, o.modify_date FROM sys.triggers AS t INNER JOIN sys.objects AS o ON o.object_id = t.object_id WHERE LIKE 'u%_AZRCRV_%'

The view can either by run manually in SQL Server Management Studio or plugged into either SmartList Designer or SmartList Builder. Once all custom items have been located, they can be extracted and preserved as scripts to be redeployed after the upgrade if necessary.