2011-11-17 77 views
0

我目前正在爲我工​​作的公司開發產品庫存信息的數據庫存儲解決方案。我正在使用MySql,而且我很難爲數據存儲提供一種高效可行的格式。MySql數據庫格式

因爲它現在工作,我們有〜25000產品跟蹤。對於每種產品,我們需要追蹤20種不同的類別(數量,價格等)。此報告每3-4天下載並更新一次,現在在Excel中存儲和更新。

我的問題是我迄今爲止提出的唯一解決方案是爲每個上述類別創建單獨的表,使用基於產品skus的外鍵和級聯來更新每個相應的表。但是,這種方法要求每次運行程序時每個表添加24000行,因爲每個產品都需要更新其運行日期。問題在於數據將存儲大約一年,所以表格將增加大量。我對其他數據庫格式的研究已經產生了一些例子,但沒有一個在這個範圍內。他們的目標是每天增加100行。

有沒有人知道或有任何想法建立這種類型的數據庫的適當方式,或者我上面描述的方法適合並在MySql表的限制內?

謝謝, 邁克

回答

0

25,000行是什麼到MySQL或這種情況下的平面文件。最初不要擔心數據量。我從事過許多零售數據庫模式,產品通常由靜態或任意長度的一組屬性定義。您的數據量結束時不會太遠。

靜態:

create table products (
    product_id integer primary key auto_increment 
    , product_name varchar(255) -- or whatever 
    , attribute1_id -- FK 
    , attribute2_id -- FK 
    , ... 
    , attributeX_id -- FK 
); 

create table attributes (
    attribute_id integer primary key -- whatever 
    , attribute_type -- Category? 
    , attribute_value varchar(255) 
); 

或者,你明明:

create table products (
    product_id integer primary key auto_increment 
    , product_name varchar(255) -- or whatever 
); 

create table product_attributes (
    product_id integer 
    , attribute_id integer 
    , -- other stuff you want like date of assignment 
    , primary key (product_id , attribute_id) 
); 

create table attributes (
    attribute_id integer primary key -- whatever 
    , attribute_type -- Category? 
    , attribute_value varchar(255) 
); 

我會毫不猶豫地推幾百萬元的記錄到喜歡的方式的基本結構。

+0

Xepoch,謝謝你的迴應。這是非常有用的,我會在開始開發這個數據庫時參考你的建議。正如我對mysql和數據庫格式的新手一樣,有經驗的老手幫助我很好。 – SubxZero