gpt4 book ai didi

mysql - 最佳实践列结构

转载 作者:行者123 更新时间:2023-11-29 22:10:29 24 4
gpt4 key购买 nike

我只是想知道当我想要软删除时这两个选项中的一个是首选?

Option 1: Creating 2 columns in my table, one named 'IsDeleted' and the other 'DeletedAt'.

When i do it like this, i first need to check if an item is deleted. Then if i need to know when it was deleted i can check that to.

Option 2: Just use 'DeletedAt' and check if its null in my code.

请激发你的回答。

最佳答案

与第二个相比,我更喜欢选项 1。让我觉得这是更好的做法是,您可以在不丢失数据的情况下操纵删除的状态。此外,每一列都将具有明确的含义,而不会创建依赖关系(决定是否删除某些内容以及何时删除某些内容),这可能会在以后阻碍您。

选项 2 将使一个列服务于它(可能)不是设计的目的,这对我来说感觉有点“肮脏”。

关于mysql - 最佳实践列结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31723921/

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