views:

86

answers:

1

I have written an O/R database wrapper that generates some wrapper methods for stored procs it reads from the database.

Now I need to produce some custom wrapper code if an input parameter of a stored proc is defaulted to NULL. The problem is - I get stored proc parameters using:

SqlCommandBuilder.DeriveParameters(command)

and it doesn't bring parameter defaults. Is there any way to look up those defaults? Are they stored anywhere in the database?

BTW, I'm using SQL Server 2008

A: 

For T-SQL stored procedures, the only means to do this is to parse the procedure definition out of the sys.sql_modules table. From the BOL on the sys.parameters table regarding the has_default_value column:

1 = Parameter has default value.

SQL Server only maintains default values for CLR objects in this catalog view; therefore, this column has a value of 0 for Transact-SQL objects. To view the default value of a parameter in a Transact-SQL object, query the definition column of the sys.sql_modules catalog view, or use the OBJECT_DEFINITION system function.

Here is an article to someone that wrote a T-SQL function that supposedly does just that: Figure Out the Default Value of Stored Procedure Parameters.

Thomas
Thanks! I suspected that I would have to parse the proc definition to get the defaults, and I'm glad someone has already done it :)
Andrey