检查两列的约束
我想将 Check Constraint
添加到服务器 2005 的表中,但无法解决。
MemberId ClubId MeetingId
1 100 10
2 100 10
3 100 10
7 101 10 <-This would throw a check constraint
1 100 11
2 100 11
我不想为一个 MeetingId
拥有多个 ClubId
基本上,ClubId
只能属于一个 MeetingId
,但可以分配多个成员。
我该如何实现这一目标?
I want to add a Check Constraint
to a table for server 2005 but cannot work it out.
MemberId ClubId MeetingId
1 100 10
2 100 10
3 100 10
7 101 10 <-This would throw a check constraint
1 100 11
2 100 11
I do not want to have more than one ClubId
for a single MeetingId
Basically a ClubId
can only belong to a single MeetingId
but can have more than one member assigned.
How do I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在检查约束中使用函数是一种选择,但您可以创建 INDEXED VIEW 完成相同的限制。
Using a function in a Check Constraint is one option but you could create an INDEXED VIEW that accomplishes the same restriction.
从msdn推断
编辑:尝试了代码并在@rippos评论后修复了它
inferred from msdn
EDIT: tried the code and fixed it after @rippos comment