2011-06-17 96 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