开发者

optimised database architecture required

开发者 https://www.devze.com 2023-03-14 01:58 出处:网络
I want to design a data开发者_如何学运维base on my website , a user can have multiple images assigned to it and one image can also have multiple users assigned to it.

I want to design a data开发者_如何学运维base

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..

how can I built this MANY TO MANY relation between the two with minimum redundancy and maximum efficiency... please suggest me a optimised architecture..


In order to implement a many-to-many relationship you need a link table. Create a 'UserImage' table that share the primary keys of both the image and User table.

This way you can check if a user has an image, or how many users an image has without working directly on the image table.


@Tim Sparg is correct... a "Link" or "Bridge" table is what you need... To elaborate more of his explanation...

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.

This way, you just need to query directly against the "UserImages" table to find things and join to the respective other to get the rest of the data...

0

精彩评论

暂无评论...
验证码 换一张
取 消