WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 479 reviews for our classroom and online training
A list of one owl's 5 favourite system stored procedures in SQL!
Part four of a six-part series of blogs

Everyone has a favourite system stored procedure (you do, don't you?). But five? That's the subject of this blog, anyway.

  1. My 5 favourite SQL system stored procedures!
  2. Listing the contents of a procedure or function (sp_helptext)
  3. Using sp_datatype_info to get the data type of a variable
  4. Which tables/procedures depend on which? (sp_depends) (this blog)
  5. Listing the columns in a table (sp_columns)
  6. Using sp_help to get help on a table, procedure, column, etc

Posted by Andy Brown on 03 February 2017

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Which tables/procedures depend on which? (sp_depends)

This is so useful that I wish I'd known it before.  You can use it in one of two main ways.

Showing what refers to a particular table

Suppose you have a table called Film, and you want to see what views, procedures, etc refer to it.  Here's how to do this:

-- what uses the films table

sp_depends 'Film'

It turns out there are two procedures and a view referencing this table:

Dependent objects

The list of objects which depend on the specified table.


Showing what tables/columns a procedure refers to

Turning the question round, here's how to show which tables and columns a particular stored procedure references:

-- what does the spExample procedure use

sp_depends 'spExample'

Here's the answer for this procedure:

Three columns

The three columns referenced by this procedure.

It even tells you if the procedure makes changes to a column!

This blog has 0 threads Add post