我有一个数据库架构,其中包括
Group{name, group.id, parent.id} with key {group.id}
在此架构中,所有parent.id都必须已经存在于group.id列中,或者为null。SQL
创建表时如何将此约束转换为?谢谢
常规外键就足够了。如果该字段为空,它将不执行任何检查。确切的语法可能会稍微取决于SQL方言,但看起来像
create table Group_ (
name varchar(30) not null,
groupid int not null primary key,
parentid int null foreign key references Group_ (groupid) )
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句