Try this
string functionCode =String.Format(@"
USE [{0}]
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
EXEC('CREATE FUNCTION fn_KeyValue
(
@tableName varchar(255),
@columnName varchar(255)
)
RETURNS varchar(100)
AS
BEGIN
DECLARE @result varchar(100)
SELECT @result = constraint_type
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS a,
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE b
WHERE a.table_name= @tableName
AND a.constraint_name=b.constraint_name
AND b.column_name = @columnName
RETURN @result
END')", Settings.Instance);