• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Script to iterate through all tables in a database

Bulldog13

Golden Member
Does anyone know of a useful script or utility to iterate through all of the tables in a given database to spit out all of its dependencies? And then even possibly pull more information out of the stored procedures as to their inputs and outputs? I am inheriting a large project with a code handoff looming this week and need some type of way to guarantee that I catch all of the information. Something like right clicking on a table, then "View Dependencies", but progmattic (lots of tables) and hopefully more robust.



Cheers !
 
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Reference the AdventureWorks database.
Dim db As Database
db = srv.Databases("AdventureWorks")
'Define a Scripter object and set the required scripting options.


That's the connection information, you would have to replace that code with one that connects to your server/database. The default constructor connects to a localhost server with default credentials.
 
USE [MYDB]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[sp_depends] TABLE1

SELECT 'Return Value' = @return_value

GO


I found this which seems to work well, how do I modify it to iterate through all the tables in a given database instead of doing it manually 1 by 1 ?

 
Originally posted by: Bulldog13
Originally posted by: KLin
http://msdn.microsoft.com/en-us/library/ms180169.aspx

define a cursor to a list of tables, set a string variable to cursor value, run SP_depends on variable, get next cursor value, set string variacle, rinse, repeat.

My T-SQL skills are very weak...care to share the code =)

I recommend doing some searched on http://groups.google.com.

You can find a lot of code examples there for everything t-sql.
 
Back
Top