2011-06-17 99 views
0

我想设计一个数据库优化的数据库架构需要

on my website , a user can have multiple images assigned to it and one image can also have multiple users assigned to it. 
one should be able to list how many images a user has Or how many users a image has. 

there will be about 1,00,000 users and 1,00,000 images.. 

我怎么能建这么多以最小冗余和最大效率两者之间有很多关系...... 请建议我一个优化的架构..

回答

0

为了实现多对多的关系,您需要一个链接表。 创建一个共享图像和用户表的主键的'UserImage'表。

通过这种方式,您可以检查用户是否有图像,或图像有多少用户没有直接在图像表上工作。

+0

感谢您的答复,但这种方法是无效的内存和访问时间方面,它也使数据库冗余...因为一个十万个方块的组合可能... – Aman 2011-06-18 06:31:56

1

@Tim SPARG是正确的......“链接”或“桥”表是你所需要的......更详细地说明了他的解释...

ImagesTable 
ImageID integer, auto-increment 
ImageOtherInfo... 

UsersTable 
UserID integer, auto-increment 
OtherUserInfo... 

UserImages 
UserImageID integer, auto-increment 
ImageID integer -- key to image table 
UserID  integer -- key to user table. 

这样,你只需要直接查询“UserImages”表中找到的东西,并加入到各自的其他数据获取其余的数据...

+0

+1的解释 – 2011-06-17 12:45:55