SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Get dependant Objects


Get dependant Objects

Author
Message
abmore
abmore
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1307 Visits: 931
Comments posted to this topic are about the item Get dependant Objects
StarNamer
StarNamer
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1968 Visits: 1992
I'd be interested if anyone could come up with a way to make SYSDEPENDS reliable.

Try the following:

create table a (id int)
go
create procedure b as begin select id from a end
go
SELECT O.id, O.name as P1, O2.name as P2, D.depid, D.depnumber
FROM sysdepends D
INNER JOIN sysobjects O ON O.id = D.id
INNER JOIN sysobjects O2 ON O2.id = D.depid
where o.name='b'
go
exec b
go
drop table a
go
create table a (id int)
go
SELECT O.id, O.name as P1, O2.name as p2, D.depid, D.depnumber
FROM sysdepends D
INNER JOIN sysobjects O ON O.id = D.id
INNER JOIN sysobjects O2 ON O2.id = D.depid
where o.name='b'
go
exec b
go
SELECT O.id, O.name as P1, O2.name as p2, D.depid, D.depnumber
FROM sysdepends D
INNER JOIN sysobjects O ON O.id = D.id
INNER JOIN sysobjects O2 ON O2.id = D.depid
where o.name='b'
go
drop table a
drop procedure b
go

The message output will be:

(1 row(s) affected)

(0 row(s) affected)

(0 row(s) affected)

(0 row(s) affected)

(0 row(s) affected)

The output indicates that SYSDEPENDS has no information on what B depends on, although it still executes OK and hence clearly depends on the recreated table A!

Derek
fahey.jonathan
fahey.jonathan
SSC Veteran
SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)

Group: General Forum Members
Points: 254 Visits: 400
Try this. It refreshes the data in sysdepends. I don't guarantee that all necessary objects are covered, just the ones I was using when I wrote this.

Yes, I know it uses a cursor and I could generate a string with the EXEC statements and execute that, but I don't see a big difference. Either way, I am executing the statements one at a time.


SELECT GETDATE()
DECLARE @Name VARCHAR(100), @Type CHAR(5)
DECLARE ModList
CURSOR FAST_FORWARD READ_ONLY FOR
SELECT xType, Name
FROM sys.sysobjects
WHERE xType IN ('P', 'FN', 'TR', 'V', 'TF')
AND Name NOT LIKE 'dt~_%' ESCAPE '~'
AND Name NOT LIKE 'jtf%'
AND Name NOT LIKE 'x~_%' ESCAPE '~'
--AND Name NOT IN ('...', '...')
ORDER BY Name
OPEN ModList
FETCH NEXT
FROM ModList
INTO @Type, @Name
WHILE @@FETCH_STATUS = 0
BEGIN -- ModList Cursor

PRINT @Type + @Name
IF @Type = 'V'
EXEC sp_refreshview @Name
ELSE
EXEC sp_refreshsqlmodule @Name

FETCH NEXT
FROM ModList
INTO @Type, @Name
END -- ModList Cursor
CLOSE ModList
DEALLOCATE ModList
SELECT GETDATE()


Iwas Bornready
Iwas Bornready
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16082 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search