Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 tsql默认值dpends在其他字段上_Sql Server 2005_Tsql - Fatal编程技术网

Sql server 2005 tsql默认值dpends在其他字段上

Sql server 2005 tsql默认值dpends在其他字段上,sql-server-2005,tsql,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 ( [

这样可能吗

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]

不可以,但您可以通过将列
timessused
(或适合您使用的任何列)设置为默认值
0
,来完成相同的任务,然后在查询中进行减法运算。

请不要用空格或任何其他要求用方括号转义名称的东西来命名列。@Adam Robinson:你说得对-我通常不这么做,但在本例中我遗漏了。