views:

74

answers:

3

I have been given access to a SQL Server database that is currently used by 3rd party app. As such, I don't have any documentation on how that application stores the data or how it retrieves it.

I can figure a few things out based on the names of various tables and the parameters that the user-defined functions takes and returns, but I'm still getting errors at every other turn.

I was thinking that it would be really helpful if I could see what the stored functions were doing with the parameters given to return the output. Right now all I've been able to figure out is how to query for the input parameters and the output columns.

Is there any built-in information_schema table that will expose what the function is doing between input and output?

A: 

Provided you have appropriate permissions, you can simply script out all Stored Procedures and Functions:

Right-click on your database in SSMS (SQL Server Management Studio), select Tasks –> Generate Scripts, ensure your database is highlighted and click next. Ensure the options to script out Stored Procedures and Functions are selected.

You can install SSMS (client Tools) without requiring a SQL Server license.

Mitch Wheat
I'm not sure I can run with this, since I don't know what SSMS is and there's a pretty good chance that means I don't have access to it. I'm just passing queries to the DB via PHP, if that helps.
Anthony
Is SSMS available for Linux-based machines? If not, this could still be an issue. I'll check it out.Thanks!
Anthony
+2  A: 

If you can execute a query against your database somehow, and if you have the necessary permissions to read the system catalog views, then you could run this query to get the name, the definition (SQL code) and a few more bits of information about your functions:

SELECT 
    obj.name ,
    obj.type ,
    obj.type_desc ,
    obj.create_date ,
    obj.modify_date ,
    m.definition ,
    m.is_schema_bound 
FROM 
    sys.objects obj
INNER JOIN 
    sys.sql_modules m ON obj.object_id = m.object_id
WHERE 
    obj.type IN ('AF', 'FN', 'FS', 'FT', 'IF', 'TF')
marc_s
+1. nice one. I always forget about these!
Mitch Wheat
I don't have the privs to see what I wanted, but this came in handy for other things.
Anthony
A: 

Another way is sp_helptext which will show you the source of the passed SP or UDF;

sp_helptext fnBlaDeBla

Alex K.