i have function and i want to create it as default
ALTER FUNCTION [dbo].[ModifiedBy]()
RETURNS varchar(50)
AS
BEGIN
RETURN host_name()
END
create default default_modifiedBy AS dbo.ModifiedBy()
User-defined functions, partition functions, and column references are not allowed in expressions in this context.
From the MSDN page for create default
:
Any constant, built-in function, or mathematical expression can be used, except those that contain alias data types. User-defined functions cannot be used
Like M.Ali writes, you can use a user-defined function if you create a column-bound default constraint with alter table ... add constraint
or create table ... (col1 default dbo.MyFunc());
.