简体   繁体   English

可以使用一个表针对多个表存储图像吗-SQL Server 2008 R2

[英]Is it okay to have one table for storing images against multiple tables - SQL Server 2008 R2

Is it okay to have one table for storing images against multiple tables? 可以有一个表来针对多个表存储图像吗? Or it is better to have a three separate tables? 还是最好有三个单独的表? Only Office can have two images. 只有Office可以有两个图像。

Schema 架构

  • Inspectors - InspectorID (PK), InspectorName Inspectors -InspectorID(PK),InspectorName

  • Offices - OfficeID (PK), OfficeName Offices -OfficeID(PK),OfficeName

  • Staff - StaffID(PK), StaffName Staff -StaffID(PK),StaffName

New Photo table (storing images in binary form for different table) 新的Photo表(以二进制形式存储图像以用于其他表)

Photos - PhotoID (PK), PhotoData, InspectorID(FK), OfficeID(FK), StaffID (FK)

New schema 新架构

  • Inspectors - InspectorID (PK), InspectorName, PhotoID(FK) Inspectors -InspectorID( PK),InspectorName, PhotoID(FK)

      or 
  • Inspectors - InspectorID (PK), InspectorName, PhotoID_1(FK) , PhotoID_2(FK) Inspectors -InspectorID (PK),InspectorName, PhotoID_1(FK)PhotoID_2(FK)

  • Offices - OfficeID (PK), OfficeName, PhotoID(FK) Offices -OfficeID( PK), OfficeNamePhotoID(FK)
  • Staff - StaffID(PK), StaffName, PhotoID(FK) Staff -StaffID(PK),StaffName, PhotoID(FK)

It's fine but you don't need FKs in both the Photo table and the other tables. 很好,但是在Photo表和其他表中都不需要FK。 Just put the PhotoID FK in the other three tables. 只需将PhotoID FK放入其他三个表中即可。

If you only have to worry about a second photo for offices, then adding a second PhotoID FK to the office table is fine. 如果您只需要担心办公室的第二张照片,则可以在办公室桌子上添加第二张PhotoID FK。

If you want a more scalable solution, and/or if a single photo could be used for more than one of the other entities, then a bridge table might be in order. 如果您想要一个更具可扩展性的解决方案,并且/或者如果一张照片可以用于多个其他实体,则可以使用桥表

OR if one photo can only ever belong to one entity, then you have a one-to-many in the opposite direction, and you can put the FK columns in the Photo table, and leave them out of the other entities tables. 或者,如果一张照片只能属于一个实体,那么您在相反的方向上一对多,则可以将FK列放在“照片”表中,而将其排除在其他实体表之外。 You might also add an "Order" column to the photo table to specify the order the photos appear for the entity, or whatever else the front end might use that information for. 您还可以在照片表中添加“订单”列,以指定照片在实体中显示的顺序,或者前端可能使用该信息的其他任何方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Win7的SQL Server 2008 R2上验证将30个表集成到一个表中的正确性? - How to verify the correctness of the integration of 30 tables into one table on SQL server 2008 R2 on win7? 如何删除SQL Server 2008 R2中所有行只有一个值的多个列 - How to remove multiple columns that have only one value across all rows in SQL Server 2008 R2 SQL Server 2008 R2表枢轴 - SQL Server 2008 R2 table Pivot SQl-将表从链接服务器复制到SQL 2008 R2上的表 - SQl - Copy tables from a linked server to a table on SQL 2008 R2 在基于第三张表的SQL Server 2008 R2中合并两张表 - Combine two tables in SQL Server 2008 R2 based on the third table 在SQL Server 2008 R2上将多个链接的服务器从一台服务器迁移到另一台服务器 - migrating multiple linked server from one server to another on sql server 2008 R2 连接具有两列的两个表SQL Server 2008 R2 - Join two tables with two columns SQL Server 2008 R2 加密SQL Server 2008 r2中现有表的列 - Encrypt column of existing tables in SQL Server 2008 r2 如何从基于临时表SQL Server 2008 R2的一个表中提取数据? - How to pull data from one table based on a temp table SQL Server 2008 R2? 检查用户帐户ad_SSmith在多个数据库上没有dbo(SQL Server 2008 R2) - check user account ad_SSmith does not have dbo on multiple database (SQL server 2008 R2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM