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


Get list of tables used in a stored procedure


Get list of tables used in a stored procedure

Author
Message
Deepthi Viswanathan Nair
Deepthi Viswanathan Nair
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 25
Comments posted to this topic are about the item Get list of tables used in a stored procedure


Kindest Regards,

Deepthi Viswanathan Nair
neela_kantam80
neela_kantam80
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 9
i am unable to get the name of tables if the storedprocedure is very long and storedprocedures using the dynamic querys can u help in this regards
naveen_yashman-703166
naveen_yashman-703166
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 19
Please note just creating the stored procedure will not bring the table names being used within the stored procedure.
To get the list of table names being used with the above said logic, the stored procedure should have been executed at least once. For e.g Exec your_sp_name parameters.
neela_kantam80
neela_kantam80
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 9
i have executed the sp but still i am unable to get the table names
neela_kantam80
neela_kantam80
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 9
i got the solution by removing depnumber=1 i am able to get the details
Jerry Hung
Jerry Hung
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1466 Visits: 1208
depnumber=1 seems to limit the outputs
but I think the purpose was to only show UNIQUE tables (example below should only show BillOfMaterials and Product)

In AdventureWorks2008 (on SQL2008)

SELECT DISTINCT
o.id, o.name AS 'Procedure_Name' , oo.name AS 'Table_Name', d.depid
--, d.depnumber -- comment this out returns unique tables only
FROM sysdepends d, sysobjects o, sysobjects oo
WHERE o.id=d.id
AND o.name= 'uspGetBillOfMaterials' -- Stored Procedure Name
AND oo.id=d.depid
--and depnumber=1
ORDER BY o.name,oo.name


returns

id Procedure_Name Table_Name depid depnumber
2123154609 uspGetBillOfMaterials BillOfMaterials 213575799 2
2123154609 uspGetBillOfMaterials BillOfMaterials 213575799 3
2123154609 uspGetBillOfMaterials BillOfMaterials 213575799 4
2123154609 uspGetBillOfMaterials BillOfMaterials 213575799 5
2123154609 uspGetBillOfMaterials BillOfMaterials 213575799 7
2123154609 uspGetBillOfMaterials BillOfMaterials 213575799 8
2123154609 uspGetBillOfMaterials Product 1717581157 1
2123154609 uspGetBillOfMaterials Product 1717581157 2
2123154609 uspGetBillOfMaterials Product 1717581157 9
2123154609 uspGetBillOfMaterials Product 1717581157 10


SQLServerNewbie

MCITP: Database Administrator SQL Server 2005
neela_kantam80
neela_kantam80
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 9
i have found that the storedprocedure id is missing in sysdepends table
but the storedprocedured is present in the database .

can any one tell me why the id's of some of the storedprocedures are not turning up in sysdepends table
neela_kantam80
neela_kantam80
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 9
storedprocedure id is present in sysobjects table but it is not there in sysdepends table can u let me know why this discrepancy
plucki duck
plucki duck
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 307
I don't seem to get any tables back if the stored procedure references linked server tables. Is there a way to remedy this?

thanks
ameya.2709
ameya.2709
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 18
hey

i have got the list of procedures, but din't get all the SP's.
also i have refreshed the DB an d checked tht. but still some of the SP's are missing from the list
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