栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

或列的外键?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

或列的外键?

检查约束可以解决这个问题。如果这是SQL Server,则将执行以下操作:

create table A (Id int not null primary key)gocreate table B (Id int not null primary key)gocreate table C (Id int not null primary key, A_Id int null, B_Id int null)goalter table C add constraint FK_C_Aforeign key (A_Id) references A (Id)goalter table C add constraint FK_C_Bforeign key (B_Id) references B (Id)goalter table C add constraint CK_C_oneIsNotNullcheck (A_Id is not null or B_Id is not null)goalter table C add constraint CK_C_oneIsNullcheck (A_Id is null or B_Id is null)go


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/441629.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号