您可能只是在单词 CONSTRAINT 之前缺少逗号分隔符!
例如)如果在下面的片段中([WorkLocationId])之后的“,”缺失,那么它将抛出 ERROR Column CHECK 约束,用于列引用另一个列错误。
这将引发错误 -
CREATE TABLE [MYSYSTEM].[User](
[UserId] int Primary key NOT NULL,
[UserName] [nvarchar](50) NULL,
[UserStatus] [nvarchar](1) NULL,
[CreatedDate] [Datetime] NOT NULL,
[WorkLocationId] int NOT NULL Foreign Key References [HRSYSTEM].[WorkLocations]([WorkLocationId])
CONSTRAINT [_UserStatusValues] CHECK ([UserStatus] IN ('A','I') )
)
这将起作用 -
CREATE TABLE [MYSYSTEM].[User](
[UserId] int Primary key NOT NULL,
[UserName] [nvarchar](50) NULL,
[UserStatus] [nvarchar](1) NULL,
[CreatedDate] [Datetime] NOT NULL,
[WorkLocationId] int NOT NULL Foreign Key References [HRSYSTEM].[WorkLocations]([WorkLocationId]),
CONSTRAINT [_UserStatusValues] CHECK ([UserStatus] IN ('A','I') )
)