Data type: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
Line 4: Line 4:


== examples of data and suggested datatype ==
== examples of data and suggested datatype ==
* birth year  
=== birth year ===
** data type: int
* data type: int
** ex: 1905 ~ 2013
* ex: 1905 ~ 2013
** range/limit: 108 yeas old<ref> Range from 1905 ~ 2013 (108 yeas old) from the Sing-up form from outlook.com {{access| date=2013-02-04}} </ref><ref>[http://zh.wikipedia.org/wiki/%E6%9C%80%E5%B9%B4%E9%95%B7%E8%80%85 最年長者 - 維基百科,自由的百科全書]: 「根據金氏世界紀錄大全紀錄的最長壽者是活了122年的雅娜·卡爾曼特」</ref>
* range/limit: 108 yeas old<ref> Range from 1905 ~ 2013 (108 yeas old) from the Sing-up form from outlook.com {{access| date=2013-02-04}} </ref><ref>[http://zh.wikipedia.org/wiki/%E6%9C%80%E5%B9%B4%E9%95%B7%E8%80%85 最年長者 - 維基百科,自由的百科全書]: 「根據金氏世界紀錄大全紀錄的最長壽者是活了122年的雅娜·卡爾曼特」</ref>




* IP(v4):
=== IP ===
** varchar(15)  
IP(v4)
** ex: 255.255.255.255 <ref>[http://stackoverflow.com/questions/1385552/datatype-for-storing-ip-address-in-sql-server Datatype for storing ip address in SQL Server - Stack Overflow]</ref>
* varchar(15)  
** range/limit:
* ex: 255.255.255.255 <ref>[http://stackoverflow.com/questions/1385552/datatype-for-storing-ip-address-in-sql-server Datatype for storing ip address in SQL Server - Stack Overflow]</ref>
 
range/limit
* IP range - Classless inter-domain routing (CIDR)<ref> [http://www.mediawiki.org/wiki/Help:Range_blocks Help:Range blocks - MediaWiki] </ref>
* IP range - Classless inter-domain routing (CIDR)<ref> [http://www.mediawiki.org/wiki/Help:Range_blocks Help:Range blocks - MediaWiki] </ref>
** 12 or 24 bytes (IPv4 and IPv6 networks)<ref> [http://www.postgresql.org/docs/8.2/static/datatype-net-types.html PostgreSQL: Documentation: Manuals: Network Address Types] </ref>
** 12 or 24 bytes (IPv4 and IPv6 networks)<ref> [http://www.postgresql.org/docs/8.2/static/datatype-net-types.html PostgreSQL: Documentation: Manuals: Network Address Types] </ref>
** ex: 69.208.0.0/32
** ex: 69.208.0.0/32


* IPv6: [http://zh.wikipedia.org/wiki/IPv6 128位元長度,以16位元為一組,每組以冒號":"隔開,可以分為8組,每組以4位元十六進制方式表示]
IPv6: [http://zh.wikipedia.org/wiki/IPv6 128位元長度,以16位元為一組,每組以冒號":"隔開,可以分為8組,每組以4位元十六進制方式表示]
** data type:
** data type:
** ex: 2001:0db8:85a3:08d3:1319:8a2e:0370:7344
** ex: 2001:0db8:85a3:08d3:1319:8a2e:0370:7344


* 網址
=== 網址 ===
** data type: >= MySQL 5.0.3 use {{kbd | key=VARCHAR(2083)}}<ref>[http://stackoverflow.com/questions/219569/best-database-field-type-for-a-url sql - Best database field type for a URL - Stack Overflow]</ref>; {{kbd | key=nvarchar(2083)}} for MS SQL  
* data type: >= MySQL 5.0.3 use {{kbd | key=VARCHAR(2083)}}<ref>[http://stackoverflow.com/questions/219569/best-database-field-type-for-a-url sql - Best database field type for a URL - Stack Overflow]</ref>; {{kbd | key=nvarchar(2083)}} for MS SQL  
** [http://support.microsoft.com/kb/208427 最大 URL 長度是在 Internet Explorer 中的 2,083 字元] for {{IE}}<ref>
* [http://support.microsoft.com/kb/208427 最大 URL 長度是在 Internet Explorer 中的 2,083 字元] for {{IE}}<ref>
* [http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers http - What is the maximum length of a URL in different browsers? - Stack Overflow]
* [http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers http - What is the maximum length of a URL in different browsers? - Stack Overflow]
* [http://wiert.me/2010/04/20/maximum-url-lengths/ Maximum URL lengths « The Wiert Corner – irregular stream of stuff]
* [http://wiert.me/2010/04/20/maximum-url-lengths/ Maximum URL lengths « The Wiert Corner – irregular stream of stuff]
</ref>
</ref>


* Chinese name:
=== Chinese name ===
** 最長姓名有13個字 <ref> 中國新聞網 (2010). [http://dailynews.sina.com/bg/tw/twpolitics/chinanews/20101104/00481967448.html 台灣“獨一姓氏”者達149人 最長姓名有13個字_台灣頻道_新浪網-北美]</ref>
** 最長姓名有13個字 <ref> 中國新聞網 (2010). [http://dailynews.sina.com/bg/tw/twpolitics/chinanews/20101104/00481967448.html 台灣“獨一姓氏”者達149人 最長姓名有13個字_台灣頻道_新浪網-北美]</ref>
** LINE姓名欄位長度限制: 15字(15個中文字或15英文字母)
** LINE姓名欄位長度限制: 15字(15個中文字或15英文字母)


* unix timestamp
=== unix timestamp ===
** bigint(10) ;  
* bigint(10) ;  
** ex: 1328664539
* ex: 1328664539
** range/limit:
* range/limit:


* School ID defined by MOE at Taiwan / 學校代碼<ref>[http://www.edu.tw/statistics/content.aspx?site_content_sn=25656 各級學校名錄--教育部統計處 Department of Statistics]{{access | date=2012-02-16}}</ref>
=== 學校代碼 ===
** integer: 4(university) ~ 6
School ID defined by MOE at Taiwan / 學校代碼<ref>[http://www.edu.tw/statistics/content.aspx?site_content_sn=25656 各級學校名錄--教育部統計處 Department of Statistics]{{access | date=2012-02-16}}</ref>
** ex: 0001(國立政治大學)、373607(臺北市立華江國小)。前面可能有零。
* integer: 4(university) ~ 6
** range/limit:  
* ex: 0001(國立政治大學)、373607(臺北市立華江國小)。前面可能有零。
* range/limit:  


* 經緯度 (經度,緯度):
=== 經緯度 (經度,緯度) ===
** DECIMAL(18,12)<ref>[http://stackoverflow.com/questions/159255/what-is-the-ideal-data-type-for-latitude-longitude mysql - What is the ideal data type for latitude / longitude? - Stack Overflow]</ref> or FLOAT( 10, 6 )<ref>[http://code.google.com/apis/maps/articles/phpsqlsearch.html Creating a Store Locator with PHP, MySQL & Google Maps - Google Maps API Family - Google Code]</ref>
* DECIMAL(18,12)<ref>[http://stackoverflow.com/questions/159255/what-is-the-ideal-data-type-for-latitude-longitude mysql - What is the ideal data type for latitude / longitude? - Stack Overflow]</ref> or FLOAT( 10, 6 )<ref>[http://code.google.com/apis/maps/articles/phpsqlsearch.html Creating a Store Locator with PHP, MySQL & Google Maps - Google Maps API Family - Google Code]</ref>
** ex: 37.401724,-122.114646
* ex: 37.401724,-122.114646
** range/limit:
* range/limit:


* 價錢/金額
=== 價錢/金額 ===
** DECIMAL(10,2)<ref> [http://stackoverflow.com/questions/628637/best-data-type-for-currency sql - Best Data Type for Currency - Stack Overflow]{{access | date=2012-03-07}} </ref>
* DECIMAL(10,2)<ref> [http://stackoverflow.com/questions/628637/best-data-type-for-currency sql - Best Data Type for Currency - Stack Overflow]{{access | date=2012-03-07}} </ref>
** ex:  
* ex:  
** range/limit: 0.00 ~ 99999999.99
* range/limit: 0.00 ~ 99999999.99


* 台灣縣市欄位值 下拉式選單<ref>取自[http://www.post.gov.tw/post/internet/f_searchzone/index.jsp?ID=190103 中華郵政全球資訊網]</ref>
=== 台灣縣市欄位值 ===
台灣縣市欄位值 下拉式選單<ref>取自[http://www.post.gov.tw/post/internet/f_searchzone/index.jsp?ID=190103 中華郵政全球資訊網]</ref>
<pre>
<pre>
$city = array("基隆市", "台北市", "新北市", "桃園縣", "新竹市", "新竹縣", "苗栗縣", "台中市",  
$city = array("基隆市", "台北市", "新北市", "桃園縣", "新竹市", "新竹縣", "苗栗縣", "台中市",  
Line 60: Line 64:
</pre>
</pre>


* 密碼
=== 密碼 ===
** varchar 允許最小8個字元長度<ref>[https://www.owasp.org/index.php/Password_length_%26_complexity Password length & complexity - OWASP] "Minimum length. Passwords should be at least eight (8) characters long." </ref>
** varchar 允許最小8個字元長度<ref>[https://www.owasp.org/index.php/Password_length_%26_complexity Password length & complexity - OWASP] "Minimum length. Passwords should be at least eight (8) characters long." </ref>


* membership
=== membership ===
** [http://msdn.microsoft.com/en-us/library/aa478949.aspx Membership Providers]
** [http://msdn.microsoft.com/en-us/library/aa478949.aspx Membership Providers]
=== 很長的文字 ===
* MySQL: {{kbd | key = TEXT}}<ref>[http://blog.longwin.com.tw/2009/10/mysql-text-field-type-length-limit-2009/ MySQL TEXT 格式 的 長度限制 - Tsung's Blog]</ref><ref>[http://dev.mysql.com/doc/refman/5.0/en/blob.html MySQL :: MySQL 5.0 Reference Manual :: 11.1.6.3 The BLOB and TEXT Types]</ref>
* MsSQL: {{kbd | key = NVARCHAR(max)}}<ref>[http://technet.microsoft.com/en-us/library/ms186939.aspx nchar and nvarchar (Transact-SQL)]</ref>


<pre> (left blank intentionally)
<pre> (left blank intentionally)

Revision as of 17:14, 3 January 2014

資料表欄位設計時,不同資料建議採用的資料型態(data type)


Web site design and development process


examples of data and suggested datatype

birth year

  • data type: int
  • ex: 1905 ~ 2013
  • range/limit: 108 yeas old[1][2]


IP

IP(v4)

  • varchar(15)
  • ex: 255.255.255.255 [3]

range/limit

  • IP range - Classless inter-domain routing (CIDR)[4]
    • 12 or 24 bytes (IPv4 and IPv6 networks)[5]
    • ex: 69.208.0.0/32

IPv6: 128位元長度,以16位元為一組,每組以冒號":"隔開,可以分為8組,每組以4位元十六進制方式表示

    • data type:
    • ex: 2001:0db8:85a3:08d3:1319:8a2e:0370:7344

網址

Chinese name

    • 最長姓名有13個字 [8]
    • LINE姓名欄位長度限制: 15字(15個中文字或15英文字母)

unix timestamp

  • bigint(10) ;
  • ex: 1328664539
  • range/limit:

學校代碼

School ID defined by MOE at Taiwan / 學校代碼[9]

  • integer: 4(university) ~ 6
  • ex: 0001(國立政治大學)、373607(臺北市立華江國小)。前面可能有零。
  • range/limit:

經緯度 (經度,緯度)

  • DECIMAL(18,12)[10] or FLOAT( 10, 6 )[11]
  • ex: 37.401724,-122.114646
  • range/limit:

價錢/金額

  • DECIMAL(10,2)[12]
  • ex:
  • range/limit: 0.00 ~ 99999999.99

台灣縣市欄位值

台灣縣市欄位值 下拉式選單[13]

$city = array("基隆市", "台北市", "新北市", "桃園縣", "新竹市", "新竹縣", "苗栗縣", "台中市", 
        "彰化縣", "南投縣", "雲林縣", "嘉義市", "嘉義縣", "台南市", "高雄市", "屏東縣", "台東縣", "花蓮縣", 
        "宜蘭縣", "澎湖縣", "金門縣", "連江縣");

密碼

    • varchar 允許最小8個字元長度[14]

membership

很長的文字

 (left blank intentionally)
* data
** data type
** ex:
** range/limit:

comparision of datatypes in different database server

Storing Unicode text[18]

  • MySQL: varchar
  • MS SQL 2008: nvarchar

DATETIME: ex: "2013-06-13 03:33:33"

  • MS SQL 2008, MySQL is equivalent

TIMESTAMP: MS SQL 2008 and MySQL is NOT equivalent[19] Icon_exclaim.gif

  • MS SQL 2008[20] ex: 0x00000000000007D3
  • MySQL ex: 2013-06-13 03:33:33

tools

ER圖(entity-relationship diagram)

references

  1. Range from 1905 ~ 2013 (108 yeas old) from the Sing-up form from outlook.com [Last visited: 2013-02-04]
  2. 最年長者 - 維基百科,自由的百科全書: 「根據金氏世界紀錄大全紀錄的最長壽者是活了122年的雅娜·卡爾曼特」
  3. Datatype for storing ip address in SQL Server - Stack Overflow
  4. Help:Range blocks - MediaWiki
  5. PostgreSQL: Documentation: Manuals: Network Address Types
  6. sql - Best database field type for a URL - Stack Overflow
  7. 中國新聞網 (2010). 台灣“獨一姓氏”者達149人 最長姓名有13個字_台灣頻道_新浪網-北美
  8. 各級學校名錄--教育部統計處 Department of Statistics[Last visited: 2012-02-16]
  9. mysql - What is the ideal data type for latitude / longitude? - Stack Overflow
  10. Creating a Store Locator with PHP, MySQL & Google Maps - Google Maps API Family - Google Code
  11. sql - Best Data Type for Currency - Stack Overflow[Last visited: 2012-03-07]
  12. 取自中華郵政全球資訊網
  13. Password length & complexity - OWASP "Minimum length. Passwords should be at least eight (8) characters long."
  14. MySQL TEXT 格式 的 長度限制 - Tsung's Blog
  15. MySQL :: MySQL 5.0 Reference Manual :: 11.1.6.3 The BLOB and TEXT Types
  16. nchar and nvarchar (Transact-SQL)
  17. SQL Server 2008 timestamp data type - Stack Overflow
  18. timestamp (Transact-SQL)

further reading