Use a UDF as the default value in a table column in SQL Server

后端 未结 1 805
萌比男神i
萌比男神i 2021-01-18 20:19

I created a scaler UDF (called sCurrentAppUser()) in SQL Server 2012 Express and I would like to use this UDF as a default value when defining a table. But every time I try,

相关标签:
1条回答
  • 2021-01-18 20:41

    You should add schema name for that function:

    CREATE TABLE [dbo].[Clients](
       [ModifyingUser] [nvarchar](128) NOT NULL DEFAULT dbo.sCurrentAppUser (),
       [Modification] [char](1) NULL DEFAULT 'A',
       [ModifyingHost] [nvarchar](128) NOT NULL DEFAULT host_name (),
       [ClientID] [uniqueidentifier] NOT NULL,
       [Label] [nvarchar](1024) NULL,
       CONSTRAINT [PK_Clients] PRIMARY KEY (
          [ClientID] ASC
       )
    )
    
    0 讨论(0)
提交回复
热议问题