哪个是数据库状态值的更好设计? [英] which is a better design for database status values?

查看:135
本文介绍了哪个是数据库状态值的更好设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到有人在设计数据库时设计了一个STATUS INT列,在其中添加了0-非活动状态,1-活动状态,2-待处理状态等值。仅进行枚举(未激活,激活,待处理)有什么区别?

I see some people design design their database having a column STATUS INT where they add values like 0- not active, 1-active, 2-pending . What is the difference between just making an enum('not active','active','pending'). Is it a better database design to not have strings defined for fields and use integers?

推荐答案

如果选项受到限制并修复使用枚举,这是更好的数据库设计,而没有为字段定义字符串并使用整数吗?直接使用(不活跃,活跃,待定)

If option are limited and fix use enum with direct ('not active','active','pending')

否则,为选项创建子表并在父表中存储对应的整数id(子表的主键)。

Otherwise it will be better to make child table for options and store corresponding integer id(Primary key of child table) in parent table.

这篇关于哪个是数据库状态值的更好设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆