tsql默认值取决于其他字段

时间:2011-04-14 12:40:26

标签: sql-server-2005 tsql

是可能的吗?

CREATE TABLE [dbo].[T_ALERT](
    [id] [bigint] NOT NULL IDENTITY(1,1),
    [times] [int] NOT NULL DEFAULT(1),
    [times left] [int] DEFAULT(times), --Here times_left get times as default
 CONSTRAINT [PK_T_ALERT] PRIMARY KEY CLUSTERED 
(
    [user_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

1 个答案:

答案 0 :(得分:1)

不,但您可以通过创建列TimesUsed(或任何适合您的用法)并将其默认为0来完成相同的操作,然后在查询中进行减法。