![]() Of course in all cases if you only want a specific type of object (stored procedures for example) in your result set then you have to either write a function (see my previous post here for an example), use OBJECTPROPERTY(IsProcedure, IsView etc) (2000+), OBJECTPROPERTYEX(BaseType) (2005+), or join with sys.objects, sys.procedures, sys.views etc. I don’t expect 2012 to add anything really new to this, but if it does I’ll be sure to add it here. SchemaA.Table1 and SchemaB.Table1 are two different objects after all. Also by requiring the schema the DMV enforces more precision in the search than the older versions. ![]() I believe the result set includes encrypted referencing objects as well, although I haven’t actually tested it. There are no longer false positives from comments, ‘ABC_DEF’ or ‘vw_ABC’ type entries. While either of the older two pieces of code will still work there is a big advantage to using the DMV. SELECT * FROM sys.dm_sql_referencing_entities('dbo.ABC', 'OBJECT') This DMV returns any object that references the object you pass it. In SQL 2008 the DMV (a Data Management Function really) sys.dm_sql_referencing_entities was added. As a result the DISTINCT in the query is no longer needed. This means that SQL stores long pieces of code in a single row instead multiple. The field sys.sql_finition is a nvarchar(max) instead of the nvarchar(4000) for. The size of the field that contains the SQL definition is the only major change that I’ve noticed between the two versions. The code I used in SQL 2005 was as follows: SELECT OBJECT_SCHEMA_NAME(object_id), OBJECT_NAME(object_id) FROM sys.sql_modules WHERE LIKE '%ABC%' Microsoft added the system view sys.sql_modules to take its place. Third if the stored procedure, view etc is encrypted then it won’t be included in the result set.Īs of SQL 2005 the table syscomments became a system view and was depreciated. Second a table ABC_DEF or a view vw_ABC, for example, will give false positives. First ABC could be listed in the comments and not in any real code. ![]() SELECT DISTINCT OBJECT_SCHEMA_NAME(id), OBJECT_NAME(id) FROM syscomments WHERE LIKE '%ABC%' This table has a column “text” that contains the “Actual text of the SQL definition statement.” Using the following statement I was able to find every piece of code in the database using the table ‘ABC’. After some research I found the system table syscomments. ![]() Many years ago when I was still working on SQL 2000 I occasionally needed to find all stored procedures and views that referenced a certain table. ![]()
0 Comments
Leave a Reply. |