SQL Server:将外键设置为特定值(SQL Server : setting foreign key to a specific value)

编程入门 行业动态 更新时间:2024-10-21 11:48:40
SQL Server:将外键设置为特定值(SQL Server : setting foreign key to a specific value)

我不确定构建问题的最佳方法是什么。

我有一个带有外键列的表。 默认情况下,外键设置为NOT NULL ,我想暂时保留它,因为这可能是最终的结果。 但是现在可能有记录不需要(并且有)外键值,我想以某种方式区分它们,所以尽可能清楚这些记录与另一些记录不同。

我试过,但似乎我不能使用bigint负数,这是我的SQL Server表中的外键的值。 我想这是非常标准的东西,除了将外键设为NULL之外,在这种情况下最好的做法是什么?

I'm not sure what is the best way to structure my question.

I have a table with foreign key column in it. By default the foreign key is set to NOT NULL and I want to keep it that way for now, because maybe this will be the final result. But for now there could be records that don't need (and have) foreign keys values and I want to distinct them somehow so it is as clear as possible that these records are something different from the other.

I tried but as it seems I can not use negative numbers for bigint which is the value of the foreign key in my SQL Server table. I guess this is pretty standard stuff so what is the best thing to do in this situation besides making the foreign key to NULL?

最满意答案

不知道为什么HABO没有得到答案,因为这几乎是你唯一的选择。

将其设为NULL 在引用的表中创建一行并将其设置为TBD或您喜欢的任何名字对象,并使用其中的ID而不是NULL

如果您的记录不需要FK且永远不会,那么您应该将列设置为NULL,否则使用临时值。

您不能使用负值,因为如果您有外键约束,您必须引用外表中的某些内容。

Not sure why HABO didn't make that the answer, because that's pretty much your only option.

Make it NULL Create a row in the referenced table and set it to TBD or whatever moniker you prefer and use the ID from that instead of NULL

If you have records that do not need an FK and never will, then you should set the column to NULL, else use a temp value.

You cannot use a negative value because you MUST reference something in the foreign table if you have a foreign key constraint.

更多推荐

本文发布于:2023-08-02 03:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1368386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   定值   Server   将外键   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!