摄影网站的关系数据库设计
我正在为摄影网站创建一个数据库,我希望它允许三个主要功能 -
允许所有者/管理员创建客户帐户和凭据,
指定哪些照片应放入网站上的三个不同的组合图库中,并且
当他们登录时向他们显示唯一客户的照片(并且仅是他们的照片!)。
这是我的第一个数据库设计 - 根据下面的回复,我添加了这一重点;)并编辑了设计如下。
图片
image_id、
文件名、
描述、
client_id、
上传日期、
用户/客户端
client_id,
客户名称
用户名,
密码,
组合
投资组合_id,
作品集名称,
PORTFOLIO_IMAGES
身份证号,
图像_id,
投资组合_id,
我是否正确地认为 PORTFOLIO_IMAGES 中的最终 id 允许我在多个图库中显示一张图像?
谢谢
I'm creating a database for a photography website and I want it to allow three main things -
Allow the owner/admin to create client accounts and credentials,
Specifying which photos should go into three different portfolio galleries on the site, and,
Displaying a unique client's photos (and only their photos!) to them when they log in.
This is my first database design ever - based on responses below, I've added that emphasis ;) and edited the design as below.
IMAGES
image_id,
filename,
description,
client_id,
date_uploaded,
USERS/CLIENTS
client_id,
client_name
username,
password,
PORTFOLIO
portfolio_id,
portfolio_name,
PORTFOLIO_IMAGES
id,
image_id,
portfolio_id,
Am I correct in thinking that the final id in PORTFOLIO_IMAGES would allow me to display one image in multiple galleries?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
因为这是您的第一个数据库设计,并且正如您在评论中可能提到的,这里缺少一些重要的东西: ER -图。这有助于理解正在发生的事情。
ER-图
同义词:User=Account、Image=Photo、Gallery=投资组合
已知角色:“管理员”、“客户端”
权利示例:“创建帐户”、“删除帐户”、“观看图像”、“添加图库”、“删除图库”、“上传图像”、“删除图像”...
表格设计
用户
图片
Image_Gallery
Gallery
User_Role
User_Right
Role
Role_Right
Right
如果通过
Role
分隔用户权限就足够了,您可能需要使用Right
删除所有内容。As it is your first DB-Design and as you may have mentioned in the comments here is something essential missing: ER-Diagram. This helps a lot understanding what's going on.
ER-Diagram
Synonyms: User=Account, Image=Photo, Gallery=Portfolio
Known Roles: "Admin", "Client"
Examples for Rights: "Create Account", "Delete Account", "Watch images", "Add Gallery", "Remove Gallery", "Upload image", "Delete image", ...
Table Design
User
Image
Image_Gallery
Gallery
User_Role
User_Right
Role
Role_Right
Right
You may want to remove all the things with
Right
if it is enough to separate user privileges byRole
.images
和users
中,您将引用客户 ID,而不是名称。images
andusers
, you will be referencing the clients id, not the name.您可能需要考虑标准化。
假设用户名是唯一的 - 两个人不能有相同的用户名,来吧 - 那么你可以消除 Users 表中的“id”,以帮助防止更新/插入/删除异常(这样做几乎肯定会让用户进入BCNF,可能还有 DKNF - 这是一件好事)。
客户很好。那么,客户和用户之间有什么区别呢?真的……和我很像。
确保使用外键约束完成引用,我认为这应该更好。
编辑:
根据新设计,我有以下建议:
将客户端/用户更改为三个表:
这是安全的,并且表示一个客户端/用户有一个名称,一个客户端/用户有一个用户名,一个用户名有一个密码。我没有看到另一种好的分解(从某种意义上说,它将采用严格的范式)。
如果需要,您可以通过消除合成的“ClientID”键来消除这些表之一。这样做有缺点,而且可能不可能(有些人确实有相同的名字!)。
这里的问题是,ClientID、ClientName 和 UserName 可能以不适合将它们填充到同一个表中的方式确定彼此。
You might want to consider normalization.
Assuming that usernames are unique - two people can't have the same username, come on - then you can eliminate "id" in the Users table in order to help prevent update/insert/delete anomalies (doing this would almost certainly put Users into BCNF, and likely DKNF - this is a good thing).
Clients is fine. What is the difference between Clients and Users, though? Really... seems similar to me.
Make sure that references are done using foreign key constraints, and I think that should be better.
EDIT:
Based on the new design, I have these suggestions:
Change Clients/Users into three tables:
This is safe and says that one Client/User has one name, one Client/User has one Username, and one Username has one Password. I don't see another good decomposition (in the sense that it's going to be in a tight normal form).
You can eliminate one of these tables by eliminating the synthetic "ClientID" key, if you want. There are disadvantages to this, and it may not be possible (some people do have the same name!).
The problem here is that it is likely that ClientID, ClientName, and UserName determine each other in a way that isn't amenable to stuffing them in the same table.
回复编辑
中提到的功能
您可以通过查询 PORTFOLIO_IMAGES 并根据需要加入图像或投资组合来在多个投资组合中使用一张图像。例如,如果您想显示婚礼作品集(伪代码)
response to edit
You can do the one image in multiple portfolios by querying PORTFOLIO_IMAGES and JOINing with images or portfolios as necessary. For example, if you want to display the wedding portfolio (psuedo-code)