数据库设计:1台或2? [英] Database design: 1 table or 2?

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

问题描述

我已经看到了一些数据库设计,它拥有一个账户表中的所有用户信息,包括密码,电子邮件,出生日期,名字,姓氏等。

I have seen a few database designs where it has all user information in an account table, including password, email, DOB, First Name, Last Name etc.

我看到了一些别人认为有两个表

I have seen some others that have two tables

用户名(或电子邮件),密码,状态(激活等),组(admin,所有者,用户等)

username(or email), password,state(activated etc), group(admin, owner, user etc)

nameFirst,nameLast,生日,birthMonth,birthYear等

nameFirst, nameLast, birthDay,birthMonth,birthYear etc

什么是亲的和上面的方法缺点是什么?

What are the pro's and cons of the above methods?

推荐答案

两种设计之间的差别主要是弹性的。如果帐户和用户数据共享一个表,则每个用户必须拥有一个账号,每个账号只能有一个用户(除非你加入另一个表,让孩子用户在除了与该帐户住用户可以添加数据,或者除非你在每个人,这是非常糟糕,对立到什么数据库应该做的)重复的帐户信息添加新记录。

The difference between the two designs is mostly one of flexibility. If the account and user data share a single table, then each user must have an account, and each account can have only one user (unless you add another table to allow child users to be added in addition to the user that lives with the account data, or unless you add new records with duplicate account details in each one, which is very bad and antithetical to what databases are supposed to do).

使用两个表,你可以很容易地在每个帐户多个用户,也可以选择允许的情况下,其中一个帐户没有用户,或者用户没有帐户,如果这样做将有利于您的用例。

With two tables, you can easily have multiple users in each account, and might also choose to allow circumstances where an account has no users, or where a user does not have an account, if doing so would benefit your use-case.

需要权衡的是,如果你想要做的事就像确定一个用户(或一个帐户的用户(S))的帐户,你必须做一个连接,如果你使用的是两个表。如果你有一个表中的所有你需要做的就是读取该行以获取这些信息。

The tradeoff is that if you want to do something like determine the account for a user (or the user(s) in an account), you have to do a join if you are using two tables. If you have one table all you have to do is fetch the row to get this information.

这篇关于数据库设计:1台或2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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