您需要使用object_definition
系统功能
select specific_name, object_definition(object_id(specific_name))
from INFORMATION_SCHEMA.ROUTINES
where routine_type = 'FUNCTION'
更新:好的,所以这不是你想要的。我刚刚错过了您需要定义 CLR 函数而不是标准的用户定义函数。实际上,我有一对可以帮助你的脚本。您可以使用它们获取 CLR 函数的参数,然后组合您需要的脚本
select
O.[object_id] as System_Object_ID,
A.Name as Assembly_Name,
ASM.assembly_class as Assembly_Class,
ASM.assembly_method as Assembly_Method,
case
when ASM.execute_as_principal_id is null then 'CALLER'
else PR.name
end as Execute_As_Name
from sys.assembly_modules as ASM with (nolock)
inner join sys.assemblies as A with (nolock) on A.[assembly_id] = ASM.[assembly_id]
inner join sys.objects as O with (nolock) on O.[object_id] = ASM.[object_id]
left outer join sys.schemas as S with (nolock) on S.[schema_id] = O.[schema_id]
left outer join sys.database_principals as PR on PR.principal_id = ASM.execute_as_principal_id
select
O.[object_id] as System_Object_ID,
P.name as Parameter_Name,
T.name as [Type_Name],
P.precision as [Precision],
P.scale as [Scale],
P.max_length as [Max_Length],
case
when P.has_default_value = 1 then isnull(cast(P.default_value as nvarchar(max)), 'null')
else null
end as Default_Value,
P.is_output as Is_Output
from sys.assembly_modules as ASM with (nolock)
inner join sys.parameters as P with (nolock) on P.[object_id] = ASM.[object_id]
inner join sys.objects as O with (nolock) on O.[object_id] = ASM.[object_id]
left outer join sys.schemas as S with (nolock) on S.[schema_id] = O.[schema_id]
inner join sys.types as T with (nolock) on T.system_type_id = P.system_type_id and T.user_type_id = P.user_type_id
或者,可能更容易,您可以只编写来自 SSMS 的对象的脚本 :)