views:

44

answers:

3

Hi,

I started working with a GPS Tracking System, whose backend logic is almost entirely based on the execution of Stored Procedures. They were implemented on a SQL 2000 database.

I received the task to document/model the existing stored procedure flow, but I don't have experience with such a task. I was used to UML, but since its focus is object-oriented programming, I don't know if it would be possible to use it here.

Is there any methodology or tool which could help me in this situation?

Regards

A: 

I'm not sure what you mean by 'flow'. Stored procedures are called by other procedures or by external programs, but there is no reason why there should be any real order of execution at the database level. The application calling the procedures determines what is called when.

Having said all that, if you mean "which stored procedures call other stored procedures?" then you could start by using sp_depends to identify the depdencies between procedures (and other objects). Ths output is not completely reliable (especially in SQL2000), and you would have to write your own script or program to loop over your procedures and assemble and present the output, but it would give you a general overview.

To do anything more than that, you would need to clarify exactly what you want to understand and document, and how your application calls the procedures.

Pondlife
Actually, the model implemented is messy: an external application calls a stored procedure. For instance, the first stored procedure performs some insert and delete statements, and then calls a second stored procedure. The cycle goes on and on, depending on which functionality is being executed (there may be third, fourth or xth procedure execution). What I want to do is document this process, maybe in a graphical way, so if someone new gets into the project, one might be able to get a picture of this flow.
born to hula
Well, you might find a tool to do some work for you but a lot depends on your code. For example, procedure names can be variables, so they might not even be present in the code anyway. And if one procedure calls another several times, then a dependency check won't tell you that. Unfortunately the SQL world is still behind other areas in terms of code analysis and so on. VS Database Edition has some nice tools, but I don't know how well SQL 2000 is supported (if at all).
Pondlife
A: 

You may start with writing some 'useful comments' in your stored procedure source. There are always some sequential instructions in any kind of code. In my experiences, if you want to understand some code, comment is the most powerful tool to use.

Here are my steps to understand the 'flow' of code:

  1. Writing the 'purpose' of the stored procedure on the top of source.
  2. Writing the 'main actions' to archive the purpose you wrote; you may 'split' the code by comments.
  3. If you need more detailed action in main action, split it in nested code.

Examples:

/**
 * 1. get the data of XXXX
 * 2. update the value of XXXXX
 * 3. ......
 */

/**
 * declare variables
 */
DECLARE ....
-- :~)

/**
 * get the value of ..... (Main action 1)
 */
SELECT @foo = f_aa
FROM ss_foo
-- :~)

/**
 * if something is in some status, do another thing ....(Main action 2)
 * or calculate the value from .....
 */
IF ....
BEGIN
   /**
    * get the data of XXXX (Sub-action 2-1)
    */
    SELECT @a = b_aa
    FROM  ss_bar
    WHERE b_cc = @foo
    -- :~)

   /**
    * calculate the XXXXX of another thing (Sub-action 2-2)
    */
    let @another = sp_another_func(@a)
    -- :~)
END
-- :~)

I think the key of writing 'useful comments' is trying to write precise context of 'business rules in computing', not writing the implementation of database components. In other words, don't write too many details in your code.

The document of bussiness rules in computing, as presented, would help you to write other documentations, and ease the maintenance of documents.

Mike Lue
A: 

Get paper + pencil + rubber and draw flows.

I am serious. Why do you need fancy gadgets for this?

vgv8
Where would I store all these pieces of paper? In a physical file? Don't wanna go back to the 80's... I asked this question to know if someone has experience with this situation and already used a *pratical* solution
born to hula