數據庫--轉載

轉載專家的:::寫的不錯--「http://rensanning.iteye.com/blog/2261645」html

首先要了解RDBMS vs. NoSQL、OLTP vs. OLAP的區別,而後要掌握如下必備知識,也能夠Google一下「Database Best Practices」看看別人的經驗總結。 

必備理論知識 
sql

  • 範式:Database Normalisation數據庫

  • 反模式:Database Anti-Patterns/Denormalization數據結構

  • 分庫分表:Shard(Partition)數據庫設計

  • 數據冗餘:Data Redundancyide

  • 科德十二定律:Codd's 12 Rulespost

命名規則 (Naming Conventions) ui

0)基本規則 編碼

所有小寫spa

下劃線分割單詞(只使用字母,數字和下劃線)

避免使用數字

避免使用保留字/關鍵字

名稱要簡單且具備描述性

1)表名 

表名用單數

2到3個單詞

最長30字符

避免縮寫簡寫(若是單詞很長能夠使用經常使用簡寫好比i18n)

關聯表使用相同前綴單詞 好比:activity_status, activity_type

避免無心義的前綴(t_、tbl_、TB_、VW_、SP_)

避免應用名前綴(MyApp_User、MyApp_Teams)

--migration用的schema_version表(當前版本,最近更新時間等) 

--編碼表/字典表/全局設置表(國家、城市、貨幣等) 

2)字段名 

是否應該全數據庫惟一?

標示表的前綴?

單字段主鍵最好用id

外鍵字段<TableName>_id

日期字段xxx_date

時間字段xxx_time

布爾字段is_xxx 或 has_xxx

避免數據類型後綴(name_tx、date_dt)

--合理選擇數字Number、時間Date的類型 

--不要存儲圖像等blob數據(必須的話不要放入頻繁訪問的表中) 

--合理設置列的寬度(使用英語之外的語言時考慮編碼) 

--用UTC的方式存儲日期與時間 

--經常使用字段(ID、狀態、刪除標誌、建立者、建立時間、更新者、更新時間) 

--姓名字段考慮外國人時要分開 

--主鍵最好爲整型值 

--越少越好(表的個數、字段個數、主鍵的字段個數) 

--在冗餘和速度之間找平衡 


如下是一些設計時常見的數據結構: 


(一)可擴展的數據模型 Extensible Data Modeling 

http://www.slideshare.net/billkarwin/extensible-data-modeling 

避免ALTER TABLE,經常使用於:CMS、EC。 

1)預留字段Extra Columns 

2)屬性表Entity-Attribute-Value 

3)序列化字段Serialized LOB & Inverted Indexes(XML/JSON/YAML等) 

4)表繼承Class Table Inheritance 

須要權衡如下內容: 

靈活性Flexible、檢索Select、過濾Filter、索引Indexed、數據類型DataTypes、約束Constraints(NOT NULL、外鍵、惟一約束等)。 


(二)基於角色的訪問控制 RBAC(Role-Based Access Control) 

用於用戶權限管理:用戶Users、用戶組Groups、角色Roles、目標Objects、訪問模式Access Mode、操做Operator。 

http://rongxh2010.iteye.com/blog/930648 


(三)層次數據 Hierarchical Data 

用於分類、組織、文件夾等。 

動態菜單Dynamic Menus的設計。 

http://www.slideshare.net/billkarwin/models-for-hierarchical-data 

http://www.slideshare.net/ehildebrandt/trees-and-hierarchies-in-sql 

http://www.sitepoint.com/hierarchical-data-database/ 


(四)ID/PK的生成策略 

http://rensanning.iteye.com/blog/2149685 


(五)密碼的存儲 Password 

http://stackoverflow.com/questions/1054022/best-way-to-store-password-in-database 


(六)多語言 Multi-Language 

多個表,多個字段、多個記錄、額外的表 

http://www.cnblogs.com/studyzy/archive/2013/04/03/2998322.html 

http://stackoverflow.com/questions/316780/schema-for-a-multilanguage-database 


(七)標籤 Tags 

http://tagging.pui.ch/post/37027745720/tags-database-schemas 


(八)歷史數據 Historical/Archive/AuditTrail 

Row級別、Column級別、Log表(操做日誌,登陸日誌) 

http://www.codeproject.com/Articles/105768/Audit-Trail-Tracing-Data-Changes-in-Database 

http://database-programmer.blogspot.com/2008/07/history-tables.html 


(九)工做流 Workflow 

http://www.exceptionnotfound.net/designing-a-workflow-engine-database-part-1-introduction-and-purpose/ 


(十)信息流/通知 Feeds/Notification/Message 

http://highscalability.com/blog/2013/10/28/design-decisions-for-scaling-your-high-traffic-feeds.html 


其餘 

下次自動登陸Remember Me

邀請碼 Invite Code

第三方登陸 Third-Party Signin


比較早的一份數據庫設計指南TechRepublic database design guide,主要針對Access的,能夠用來參考。

相關文章
相關標籤/搜索