[英]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), OfficeName , PhotoID(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.