摄影网站的关系数据库设计

发布于 2024-11-30 07:03:52 字数 560 浏览 2 评论 0原文

我正在为摄影网站创建一个数据库,我希望它允许三个主要功能 -

允许所有者/管理员创建客户帐户和凭据,
指定哪些照片应放入网站上的三个不同的组合图库中,并且
当他们登录时向他们显示唯一客户的照片(并且仅是他们的照片!)。

这是我的第一个数据库设计 - 根据下面的回复,我添加了这一重点;)并编辑了设计如下。

图片
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

随风而去 2024-12-07 07:03:52

因为这是您的第一个数据库设计,并且正如您在评论中可能提到的,这里缺少一些重要的东西: ER -图。这有助于理解正在发生的事情。

ER-图

在此处输入图像描述

同义词:User=Account、Image=Photo、Gallery=投资组合
已知角色:“管理员”、“客户端”
权利示例:“创建帐户”、“删除帐户”、“观看图像”、“添加图库”、“删除图库”、“上传图像”、“删除图像”...

表格设计

用户

  • ID
  • 名称
  • 密码

图片

  • id
  • user_id
  • 文件
  • 名 说明
  • upload_date

Image_Gallery

  • image_id
  • gallery_id

Gallery

  • ID
  • 名称

User_Role

  • user_id
  • role_id

User_Right

  • user_id
  • right_id

Role

  • ID
  • 名称

Role_Right

  • role_id
  • right_id

Right

  • ID
  • 名称

如果通过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

enter image description here

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

  • id
  • name
  • password

Image

  • id
  • user_id
  • filename
  • description
  • upload_date

Image_Gallery

  • image_id
  • gallery_id

Gallery

  • id
  • name

User_Role

  • user_id
  • role_id

User_Right

  • user_id
  • right_id

Role

  • id
  • name

Role_Right

  • role_id
  • right_id

Right

  • id
  • name

You may want to remove all the things with Right if it is enough to separate user privileges by Role.

ㄖ落Θ余辉 2024-12-07 07:03:52
  1. 在表 imagesusers 中,您将引用客户 ID,而不是名称。
  2. 我会为画廊创建一个单独的表格,因为客户往往每三个月就会有新的愿望。所以您可能需要添加更多画廊。
    • 表“画廊”
      • ID
      • 姓名
    • 表“image_is_in_gallery”
      • 图片 ID
      • gallery_id
      • PRIMARY(image_id、gallery_id)
  1. Within the tables images and users, you will be referencing the clients id, not the name.
  2. I would create a separate table for the galleries, as clients tend to have new wishes every three month. So you maybe need to add more galleries.
    • table "galleries"
      • id
      • name
    • table "image_is_in_gallery"
      • image_id
      • gallery_id
      • PRIMARY(image_id, gallery_id)
你如我软肋 2024-12-07 07:03:52

您可能需要考虑标准化。

假设用户名是唯一的 - 两个人不能有相同的用户名,来吧 - 那么你可以消除 Users 表中的“id”,以帮助防止更新/插入/删除异常(这样做几乎肯定会让用户进入BCNF,可能还有 DKNF - 这是一件好事)。

客户很好。那么,客户和用户之间有什么区别呢?真的……和我很像。

确保使用外键约束完成引用,我认为这应该更好。

编辑:

根据新设计,我有以下建议:

将客户端/用户更改为三个表:

  ClientNames
  - ClientID (PK)
  - ClientName

  ClientUsernames
  - ClientID (PK)
  - Username

  UsernamePasswords
  - Username (PK)
  - Password

这是安全的,并且表示一个客户端/用户有一个名称,一个客户端/用户有一个用户名,一个用户名有一个密码。我没有看到另一种好的分解(从某种意义上说,它将采用严格的范式)。

如果需要,您可以通过消除合成的“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:

  ClientNames
  - ClientID (PK)
  - ClientName

  ClientUsernames
  - ClientID (PK)
  - Username

  UsernamePasswords
  - Username (PK)
  - Password

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.

少女七分熟 2024-12-07 07:03:52
  1. 在 images 和 users 表上使用 client id 而不是 client_name
  2. 添加另一个表,portfolio 至少包含 name 和 id 列
  3. 添加另一个表,portfolio_images,包含两列 image_id 和 Portfolio_id。这将允许@Alex 在评论

回复编辑
中提到的功能
您可以通过查询 PORTFOLIO_IMAGES 并根据需要加入图像或投资组合来在多个投资组合中使用一张图像。例如,如果您想显示婚礼作品集(伪代码)

SELECT filename,... 
FROM images img
INNER JOIN portfolio_images pimg on img.image_id = portfolio_images.image_id
WHERE pimg.portfolio_id = <whatever the id is for wedding portfolio>
  1. use client id instead of client_name on the images and users table
  2. Add another table, portfolio with at least name and id columns
  3. Add another table, portfolio_images with two columns, image_id and portfolio_id. This will allow the feature mentioned by @Alex in the comments

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)

SELECT filename,... 
FROM images img
INNER JOIN portfolio_images pimg on img.image_id = portfolio_images.image_id
WHERE pimg.portfolio_id = <whatever the id is for wedding portfolio>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文