在这种情况下如何为 2 个 SQL Server 表定义引用完整性?
我在 SQL Server 2005 中有 2 个表,如下
表 A
- ActionID (PK,int, not null)
- ProgressID (uniqueidentifier,not null)
- ReferID (uniqueidentifier, not null)
- Field XYZ (varchar(50), not null)
- Field MNO (tinyint) , not null)
Table B
- TrackID (PK,int, not null)
- ProgressID (uniqueidentifier,not null)
- ReferID (uniqueidentifier, not null)
- Field ABC (varchar(20), not null)
- Field EFG (datetime, not null)
现在我有一个具体问题:
两个表中的 ProgressID
引用相同的实体。我想建立一个积分关系,以便当表 B 中存在值时,不可能删除表 A 中的 ProgressID
。如何做到这一点?
I have 2 tables in SQL Server 2005 as follows
Table A
- ActionID (PK,int, not null)
- ProgressID (uniqueidentifier,not null)
- ReferID (uniqueidentifier, not null)
- Field XYZ (varchar(50), not null)
- Field MNO (tinyint, not null)
Table B
- TrackID (PK,int, not null)
- ProgressID (uniqueidentifier,not null)
- ReferID (uniqueidentifier, not null)
- Field ABC (varchar(20), not null)
- Field EFG (datetime, not null)
Now I have a specific question:
The ProgressID
in both the tables refer to the same entity. And I want to establish an integral relationship so that Deletion of ProgressID
in Table A is not possible when value exisits in Table B. How to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会为此推荐一个删除前触发器。就像
我不知道有什么约束可以强制执行您想要的那样。
I would recommend a before delete trigger for this. Something like
I do not know of a constraint that will enforce what you would like.