我有下表:
CREATE TABLE [dbo].[EntityAttributeRelship](
[IdNmb] [int] IDENTITY(1,1) NOT NULL,
[EntityIdNmb] [int] NOT NULL,
[AttributeIdNmb] [int] NOT NULL,
[IsActive] [bit] NOT NULL CONSTRAINT [DF_EntityAttributeRelship_IsActive] DEFAULT ((0)),
CONSTRAINT [PK_EntityAttributeRelship] PRIMARY KEY CLUSTERED
([IdNmb] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]
表中的部分数据如下所示:
IdNmb EntityIdNmb AttributeIdNmb IsActive
1 22 7 0
2 22 8 0
3 22 9 0
4 22 10 1
如果已经存在 IsActive = 1 的 EntityIdNmb 记录,我想添加一个约束以确保没有人添加或更新记录以使 IsActive = 1。
我该怎么做呢?