Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem: Find all table names in db and then find

Author  Topic 

olivia2008
Starting Member

3 Posts

Posted - 2008-06-12 : 03:41:22
I have 3 database say
db1
db2
db3

I need to setup a script to read all the table names in the database above and then query the database to find the list of Stored Procedure using each table.(SQL Server)

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-06-12 : 03:56:31
To get a list of user tables in each database, run:

select * from sys.objects where type = 'U'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-12 : 04:02:08
EXEC sp_msforeachdb to execute script for each db

use SELECT * FROM INFORMATION_SCHEMA.TABLES to get table names in each db
use sp_depends TableNAme to get dependent stored procedures for each table.
Go to Top of Page

olivia2008
Starting Member

3 Posts

Posted - 2008-06-12 : 04:19:23
CANT IT BE DONE IN A SINGLE STORED PROCEDURE USING CURSOR?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-12 : 04:22:05
quote:
Originally posted by olivia2008

CANT IT BE DONE IN A SINGLE STORED PROCEDURE USING CURSOR?


You can. Put the statements provided inside a stored procedure. You might require a table to put results of SELECT query and then need to loop on it using while loop and execute sp_depends from within the loop.
Go to Top of Page

olivia2008
Starting Member

3 Posts

Posted - 2008-06-12 : 04:30:09
quote:

You can. Put the statements provided inside a stored procedure. You might require a table to put results of SELECT query and then need to loop on it using while loop and execute sp_depends from within the loop.




WOULD BE THANKFUL TO YOU IF YOU CAN DEMONSTRATE WITH EXAMPLE.I AM VERY MUCH NEW TO SQL SERVER.YOUR HELP WILL BE HIGHLY APPRICIATED
Go to Top of Page
   

- Advertisement -