鍍金池/ 問答/PHP  數(shù)據(jù)庫/ 請教分類信息字段設(shè)計

請教分類信息字段設(shè)計

請教一個分類信息的數(shù)據(jù)庫怎么設(shè)計比較好?

自己想把信息主要內(nèi)容(title,content)都寫在一張info表里,不知道怎么對特殊屬性怎么設(shè)計表?

category 表 - 房產(chǎn) 工作分類

info 表 房產(chǎn)工作汽車等信息

  • id categoryId title content

分類信息包含房產(chǎn),工作等等,但是每個不同類型的特殊屬性又不一樣,房產(chǎn)有面積,小區(qū),工作有職位,福利等等
但是 meta 表不知道怎么設(shè)計?求解或者怎么好

A 方案

id metaname metavalue infoId
面積。 120
小區(qū)小區(qū)。 小區(qū)名稱
職位。 銷售

或者 B 方案 這個感覺字段會很多,因為不止房產(chǎn)工作,還有汽車等等

id 面積 小區(qū) 職位 infoId
120 名稱 銷售

=================

更新自己設(shè)計的表,后面有人有更好的請指教

+-------------------+
| Tables            |
+-------------------+
| houses            |
| informations      |
| jobs              |
| category          |
+-------------------+

informations table
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| title      | varchar(255)     | NO   |     | NULL    |                |
| content    | text             | YES  |     | NULL    |                |
| category_id| int(10) unsigned | NO   | MUL | NULL    |                |
| field_id   | int(10) unsigned | NO   |     | NULL    |                |
| field_type | varchar(10)      | NO   |     |         |                |
+------------+------------------+------+-----+---------+----------------+

houses table
+--------------+------------------+------+-----+---------+----------------+
| Field        | Type             | Null | Key | Default | Extra          |
+--------------+------------------+------+-----+---------+----------------+
| id           | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| layout_shi   | tinyint(4)       | NO   |     | NULL    |                |
| layout_ting  | tinyint(4)       | NO   |     | NULL    |                |
| layout_wei   | tinyint(4)       | NO   |     | NULL    |                |
| area         | smallint(6)      | NO   |     | NULL    |                |
+--------------+------------------+------+-----+---------+----------------+

jobs table
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| gangwei     | varchar(255)     | NO   |     | NULL    |                |
| company     | varchar(255)     | NO   |     | NULL    |                |
| address     | varchar(255)     | NO   |     | NULL    |                |
| fuli        | varchar(255)     | YES  |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+

informations 表中的 field_id 為 houses 或者 jobs 的 id,field_type 為 houses 或者 jobs。
informations 與 houses、jobs 多態(tài)關(guān)聯(lián)

我正在學(xué)習(xí) laravel,所以大致就是這樣,

回答
編輯回答
獨白

1.房產(chǎn)-工作表
分類ID 房產(chǎn)信息ID 工作信息ID

2.房產(chǎn)表
房產(chǎn)信息ID 屬性1 屬性2 ……

3.工作表

工作信息ID 屬性1 屬性2 ……

2017年10月19日 13:19
編輯回答
胭脂淚

不是很明白你的需求。

2017年9月21日 04:11
編輯回答
悶油瓶

大概知道你的意思了,你自己的設(shè)計其實就是想把公用的交給抽象模型,我是不建議在存儲層這樣去設(shè)計的,各個類別的模型屬性本身就有很多不一樣,冗余的話也不是不可以,但是不利于以后擴(kuò)展,每個分類單獨建表吧,你所想的抽象留在應(yīng)用層去抽象模型挺好的。都堆在一個表里對擴(kuò)展和修改太不友好,望對你有幫助。

2017年11月30日 00:43