I'm testing out some SQL CLR stuff in VS 2008 and SQL Server 2005, how do I install a user defined function on the database? I built it and have the DLL, but now what?
1 Answer
You would use CREATE ASSEMBLY. e.g.:
CREATE ASSEMBLY MyAssembly FROM 'C:\path\fille.dll' WITH PERMISSION_SET = SAFE;
GO
And then optional syntax for CREATE FUNCTION that references the function in your assembly (the external name will be dependent on how you structured your code):
CREATE FUNCTION dbo.MyFunction(@param <data_type>)
RETURNS <data_type>
AS EXTERNAL NAME MyAssembly.SqlServerFunctions.FunctionName;
CREATE ASSEMBLY. One of the first Google hits: msdn.microsoft.com/en-us/library/ms254956(v=vs.90).aspxCREATE FUNCTION ... EXTERNAL NAME(that example uses a procedure but the syntax is the same).