December 31, 2005 at 4:14 am
December 31, 2005 at 11:17 am
1 and 2 - sysdepends. It can be out of date, but Red Gate software has a tool to help you determine this.
3 - you can search in syscomments for this, but there isn't an easy way to find it.
January 2, 2006 at 4:01 am
sp_depends storedprocedurename
This would give all the dependent objects of the Stored procedure ..
January 4, 2006 at 4:12 pm
Be careful with sp_depends. It does not report dependent objects that exist in databases other than your current database - i.e. if you have a cross database query in your proc you won't see the "remote" tables.
January 5, 2006 at 2:13 pm
I created few little SPs to help me with some of what you trying to do. They work for me but you may have to modify them to fit your needs.
CREATE PROCEDURE sa_FindObjectDependency
@ObjectName VARCHAR(50)
AS
SELECT DISTINCT name
FROM sysobjects SO
INNER JOIN syscomments SC ON SC.id = SO.id
WHERE ( text LIKE '%' + @ObjectName + '(%'
OR text LIKE '% ' + @ObjectName + ' %'
OR text LIKE '%.' + @ObjectName + CHAR(13) + CHAR(10) + '%'
OR text LIKE '% ' + @ObjectName + ' %'
OR text LIKE '%.' + @ObjectName + CHAR(13) + CHAR(10) + '%')
AND name <> @ObjectName
ORDER BY name
GO
CREATE PROCEDURE sa_FindFieldDependency
@TableName VARCHAR(50),
@FieldName VARCHAR(50)
AS
SELECT DISTINCT name
FROM syscomments SC
INNER JOIN sysobjects SO ON SC.id = SO.id
INNER JOIN syscomments SC1 ON SC.id = SC1.id AND SC1.text LIKE '%' + @TableName + '%'
WHERE SC.text LIKE '%' + @FieldName + '%'
ORDER BY name
The second one is less robust because of the way my tables and fields are named. You may have to use the ORing on the text fields from the first SP in the second one to get this to a level of usability you need.
---------------------------------------------
[font="Verdana"]Nothing is impossible.
It is just a matter of time and money.[/font]
January 12, 2006 at 10:06 pm
Oh, Thank you very much. This script really works fine. It works good. Thanks for the reply.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply