Naor
Naor

Reputation: 24053

tsql default value dpends on other field

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(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]

Upvotes: 0

Views: 281

Answers (1)

Adam Robinson
Adam Robinson

Reputation: 185593

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.

Upvotes: 1

Related Questions