gpt4 book ai didi

sql-server - 对同一个表中的 RowParentId 的约束?

转载 作者:行者123 更新时间:2023-12-03 16:46:50 24 4
gpt4 key购买 nike

如何在我的字段上指定允许 null 的约束,但如果值存在,它应该是现有表中主键的值之一?看一下代码:

  CREATE TABLE TestTable 
(
RowId int IDENTITY NOT NULL PRIMARY KEY,
RowParentId int NULL, -- < how do I specify constraint that RowParentId if not NULL should be RowId (foreign key to existing table?)
RowName nvarchar(30),
RowShortName nvarchar(10)
)
GO

我希望能够在不限制深度和对现有父 View 强制约束的情况下生成父 subview 。

希望我能够传达我正在寻找的东西。

干杯

最佳答案

那不就是个外键吗?

RowParentId int NULL references ParentTable (ParentTableIdColumn),

如果它不为空,那么它必须是来自父表的值。

关于sql-server - 对同一个表中的 RowParentId 的约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/757918/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com