Debugging a storedprocedure in SQL 2005

  • [font="Comic Sans MS"]How to debug a stored procedure in SQL 2005?[/font]

  • It seems it is not available in SQL 2005. It is available in 2008 though. Please see this link.

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3909125&SiteID=1

  • Like most items in SQL Server the answer is "It depends".

    a. Is the SP reporting an error?

    b. Is the SP returning invalid / incomplete data?

    Using SSMS

    In either case use the Print statement to print the value of passed parameters (if any).

    Periodically insert Print statements to show progress through the SP.

    If a long complex SP and it is reporting an error simplify the SP and gradually add complexity.

    If the SP uses a sub query, check what is returned by the sub query.

    If it is taking too long to return results run show plan to determine if it is performing table scans rather that using indexes.

    Of course all of the above should be performed on a development server and NOT a production server.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Execution plans are your friend.

    They will show what the query is doing inside the engine. From there you can determine if you need indexes etc. If the data is not correct, you'll have to check your logic, which is a different issue.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply