【发布时间】:2018-09-15 00:29:21
【问题描述】:
我不希望根据以下条件在表中允许重复
例如: 我有
ID Number AdditionalID
1 458 1234 <-- 458 must be allow
2 458 1234 <-- 458 must be allow
3 458 123456 <-- 458 must not be allowed because additionalID is different
4, 459 ,123456
【问题讨论】:
-
为什么 id 1 和 id 2 允许使用 458 而 id 3 却不允许使用 458?
-
您使用的是哪个DBMS? “SQL”只是一种查询语言,而不是特定数据库产品的名称。请为您正在使用的数据库产品添加标签
postgresql、oracle、sql-server、db2、... -
SQL EXPRESS 2014
-
@jarlh ID 是简单的主键:这将始终以 1 递增(我不在乎)458 可以存在多次,而附加 ID 相同,如果传入的数字是 458然后必须删除 AdditionalID IS Different
-
如果 458 必须始终与 1234 匹配,为什么不将其作为 single 事实存储在其他表的 single 行中,然后从该表中删除的那些列之一?可以实现此约束,但如果您对数据进行规范化,则不需要。
标签: sql sql-server constraints filtering sql-server-express