开发者

tsql default value dpends on other field

开发者 https://www.devze.com 2023-02-24 10:11 出处:网络
is something like that possible ? CREATE TABLE [dbo].[T_ALERT]( [id] [bigint] NOT NULL IDENTITY(1,1), [times] [int] NOT NULL DEFAULT(1),

is something like that possible ?

CREATE TABLE [dbo].[T_ALERT](
    [id] [bigint] NOT NULL IDENTITY(1,1),
    [times] [int] NOT NULL DEFAULT(1),
    [times left] [int] DEFAULT(ti开发者_如何学JAVAmes), --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]


No, but you can accomplish the same thing by making the column TimesUsed (or whatever is appropriate for your usage) and defaulting it to 0, then just doing subtraction in your query.

0

精彩评论

暂无评论...
验证码 换一张
取 消