定义“ENUM”的最佳方式是什么?在Oracle 10中创建表时的数据类型?
例如:我想要一个名为 season 的数据类型 (= { spring, Summer, Fall, Winter}
For example: I want a data type called season (= { spring, summer, fall, winter}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
定义一个
season
表,有两列:season_id
和season_name
:添加一个
season_id
列到记录需要季节标识的表,并创建与season
表的外键关系CHECK 约束是下一个选择,但如果您想使用多个表中的值,则很糟糕,因为它们无法集中管理。触发器也是一种选择,但在这种情况下,与 CHECK 约束相比,触发器更像是杀死蚊子的大炮……
哪个最好?
引用 sql_mommy 的话:
Define a
season
table, having two columns:season_id
, andseason_name
:Add a
season_id
column to table(s) whose records need season identification, and create a foreign key relationship to theseason
tableCHECK constraints are the next option, but suck if you want to use the values in more than one table because they can't be centrally managed. Triggers are also an option, but in this case triggers are more like a cannon to kill a mosquito compared to a CHECK constraint...
Which is best?
To quote sql_mommy: