PRB: Errors Creating Recursive Stored Procedures

Last reviewed: April 25, 1997
Article ID: Q64241

The information in this article applies to:

  - Microsoft SQL Server version 4.2 for OS/2

SYMPTOMS

The following SQL Server error (#2007) occurs when you try to create a procedure, "add task," that is recursive on itself:

   SQL error: cannot add rows to sysdepends for current stored
   procedure because it depends on missing object "add task." The
   stored procedure will still be created.

CAUSE

This error is produced when SQL Server attempts to normalize your procedure to produce a query tree for future execution of your SQL statements. Before your stored procedure is created, it does not understand any reference to itself.

Although stored procedures are reusable, they are not reentrant; therefore, there is no way to call the procedure from within itself. The error that you are encountering is due to the stored procedure rule on page 292 of the "Microsoft SQL Server Transact-SQL User's Guide" for version 4.2, which states the following:

   You can reference an object you've created in the same
   procedure as long as it is created before it is referenced.

WORKAROUND

If you need a single level of recursion only, this can be simulated by creating a separate procedure that has the same functionality. After it has been created, your first stored procedure can be modified to execute the second procedure when necessary.


Additional query words:
Keywords : kbother SSrvServer SSrvStProc
Version : 4.2
Platform : OS/2
Issue type : kberrmsg


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.