IF EXISTS(SELECT name FROM sysobjects WHERE name = N'test_table' AND type = 'U') DROP TABLE test_table GO CREATE TABLE test_table ( c1 VARCHAR(255) NULL) GO IF EXISTS (SELECT name FROM sysobjects WHERE name = N'test_PRoc1' AND type = 'P') DROP PROCEDURE test_proc1 GO CREATE PROCEDURE test_proc1 @name sysname = NULL AS IF @name IS NOT NULL BEGIN INSERT test_table VALUES (@name) END ELSE BEGIN RETURN END GO IF EXISTS (SELECT name FROM sysobjects WHERE name = N'test_proc2' AND type = 'P') DROP PROCEDURE test_proc2 GO CREATE PROCEDURE test_proc2 AS DECLARE @myVar sysname SELECT @myVar = name FROM sysobjects WHERE id = 1 EXEC test_proc1 @myVar GO EXEC sp_depends test_proc1 GO DROP PROCEDURE test_proc2, test_proc1 GO DROP TABLE test_table GO