急救

tanmu 2003-12-21 04:50:47
各位大侠:


现在我有两个表:A,B
现在B表中的某个非主键for_index只有两个情况:
1:为空
2:为A表的主键。
可是我不知道怎么办,是建个约束??规则??
请各位救救我!!!!!!!!
...全文
31 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzh1215 2003-12-21
  • 打赏
  • 举报
回复
--建两个触发器,主表一个,从表一个。
主表的:
create trigger AA on A
FOR DELETE
AS
delete from B
where id in(select id from deleted)
GO
create trigger BB on B
FOR INSERT
AS
if not exists(select id from B,A where a.id=b.id)
or (select id from inserted)=NULL
rollback tran
GO
playyuer 2003-12-21
  • 打赏
  • 举报
回复
允许为空Null 的index 是不支持的
tanmu 2003-12-21
  • 打赏
  • 举报
回复
做个约束可以吗?
飞扬的梦
shuiniu 2003-12-21
  • 打赏
  • 举报
回复
你想干什么?

22,299

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧