我正在尝试为简历建模实体,这样做我遇到了以下问题:除了最近担任的职位外,所有职位都有结束日期。
有没有一种好方法可以限制最多允许为空的一行。更好的情况是单个允许的 null 也具有最新的开始日期。
另一种说法是你能指定一个“not null unless”的约束吗?
注意:这是我正在做的学习练习(而不是处理生产代码)。这是我正在使用的脚本表:
CREATE TABLE [dbo].[Employers](
[Id] [uniqueidentifier] NOT NULL,
[City] [nvarchar](max) NULL,
[State] [nvarchar](max) NULL,
[StartMonth] [int] NULL,
[StartYear] [int] NOT NULL,
[EndMonth] [int] NULL,
[EndYear] [int] NULL,
[Name] [nvarchar](max) NULL,
[Label] [nvarchar](max) NULL,
[Resume_Id] [uniqueidentifier] NULL,
[UserProfile_UserId] [int] NULL,
PRIMARY KEY CLUSTERED
(
[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] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Employers] WITH CHECK ADD CONSTRAINT [Resume_Employers] FOREIGN KEY([Resume_Id])
REFERENCES [dbo].[Resumes] ([Id])
GO
ALTER TABLE [dbo].[Employers] CHECK CONSTRAINT [Resume_Employers]
GO
ALTER TABLE [dbo].[Employers] WITH CHECK ADD CONSTRAINT [UserProfile_Employers] FOREIGN KEY([UserProfile_UserId])
REFERENCES [dbo].[UserProfile] ([UserId])
GO
ALTER TABLE [dbo].[Employers] CHECK CONSTRAINT [UserProfile_Employers]
GO