Quite 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:
CREATE VIEW uv_AZRCRV_GetCustomObjects AS/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
*/SELECT o.name,''AS'table name', o.type_desc, o.modify_date FROMsys.objectsAS o WHERE o.name LIKE'u__AZRCRV_%'UNIONALLSELECT i.name, o.name, o.type_desc, o.modify_date FROMsys.indexesAS i INNER JOINsys.objectsAS o ON o.object_id= i.object_idWHERE I.name LIKE'u%_AZRCRV_%'UNIONALLSELECT t.name, o.name, t.type_desc, o.modify_date FROMsys.triggersAS t INNER JOINsys.objectsAS o ON o.object_id= t.object_idWHERE o.name 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.
Read original post Find All Custom SQL Objects In Database at azurecurve|Ramblings of a Dynamics GP Consultant