SQL數據類型說明和MySQL語法示例

SQL數據類型 (SQL Data Types)

Each column in a database table is required to have a name and a data type.

數據庫表中的每一列都必須具有名稱和數據類型。

An SQL developer must decide what type of data that will be stored inside each column when creating a table. The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data.

SQL開發人員必須確定在創建表時將在每一列內存儲的數據類型。 數據類型是SQL理解每列內部期望的數據類型的指南,并且還確定SQL將如何與存儲的數據進行交互。

MySQL數據類型 (MySQL Data Types)

SQL general data types consist of the following:

SQL常規數據類型包括以下內容:

  1. A text- and/or numeric-based value, often referred to as a STRING

    基于文本和/或數字的值,通常稱為“ STRING”
  2. A numeric-only value, often referred to as an INTEGER

    僅數字值,通常稱為INTEGER
  3. A calendar- and/or clock-based value, often reffered to as DATE or TIME

    基于日歷和/或時鐘的值,通常為DATE或TIME
  4. A database-specific value such as a boolean (two-option) flag, an array that stores multiple values within one data point

    特定于數據庫的值,例如布爾(雙選項)標志,該??數組在一個數據點內存儲多個值

文字數據類型: (Text data types:)

Data typeDescription
CHAR(size)Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters
VARCHAR(size)Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters. Note: If you put a greater value than 255 it will be converted to a TEXT type
TINYTEXTHolds a string with a maximum length of 255 characters
TEXTHolds a string with a maximum length of 65,535 characters
BLOBFor BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data
MEDIUMTEXTHolds a string with a maximum length of 16,777,215 characters
MEDIUMBLOBFor BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data
LONGTEXTHolds a string with a maximum length of 4,294,967,295 characters
LONGBLOBFor BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data
ENUM(x,y,z,etc.)Let you enter a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted. Note: The values are sorted in the order you enter them. You enter the possible values in this format: ENUM(‘X’,‘Y’,‘Z’)
SETSimilar to ENUM except that SET may contain up to 64 list items and can store more than one choice
數據類型 描述
CHAR(大小) 持有固定長度的字符串(可以包含字母,數字和特殊字符)。 固定大小在括號中指定。 最多可存儲255個字符
VARCHAR(大小) 包含可變長度的字符串(可以包含字母,數字和特殊字符)。 最大大小在括號中指定。 最多可以存儲255個字符。 注意:如果您輸入的值大于255,它將轉換為TEXT類型
細語 包含最大長度為255個字符的字符串
文本 包含最大長度為65,535個字符的字符串
BLOB 對于BLOB(二進制大對象)。 最多可容納65,535個字節的數據
中文字 包含最大長度為16,777,215個字符的字符串
中號 對于BLOB(二進制大對象)。 最多可容納16,777,215字節數據
長文本 包含最大長度為4,294,967,295個字符的字符串
龍寶 對于BLOB(二進制大對象)。 最多可容納4,294,967,295字節的數據
枚舉(x,y,z等) 讓您輸入可能值的列表。 您最多可以在ENUM列表中列出65535個值。 如果插入的值不在列表中,則將插入空白值。 注意:值將按照您輸入的順序進行排序。 您可以使用以下格式輸入可能的值:ENUM('X','Y','Z')
與ENUM相似,但SET最多可以包含64個列表項,并且可以存儲多個選項

數字數據類型: (Number data types:)

Data typeDescription
TINYINT(size)-128 to 127 normal. 0 to 255 UNSIGNED*. The maximum number of digits may be specified in parenthesis
SMALLINT(size)-32768 to 32767 normal. 0 to 65535 UNSIGNED*. The maximum number of digits may be specified in parenthesis
MEDIUMINT(size)-8388608 to 8388607 normal. 0 to 16777215 UNSIGNED*. The maximum number of digits may be specified in parenthesis
INT(size)-2147483648 to 2147483647 normal. 0 to 4294967295 UNSIGNED*. The maximum number of digits may be specified in parenthesis
BIGINT(size)-9223372036854775808 to 9223372036854775807 normal. 0 to 18446744073709551615 UNSIGNED*. The maximum number of digits may be specified in parenthesis
FLOAT(size,d)A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
DOUBLE(size,d)A large number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
DECIMAL(size,d)A DOUBLE stored as a string , allowing for a fixed decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
數據類型 描述
天晴(尺碼) -128至127正常。 0至255 UNSIGNED *。 可以在括號中指定最大位數
SMALLINT(大小) -32768至32767正常。 0到65535 UNSIGNED *。 可以在括號中指定最大位數
MEDIUMINT(大小) -8388608至8388607正常。 0到16777215 UNSIGNED *。 可以在括號中指定最大位數
INT(尺寸) -2147483648至2147483647正常。 0至4294967295 UNSIGNED *。 可以在括號中指定最大位數
BIGINT(大小) -9223372036854775808至9223372036854775807正常。 0至18446744073709551615未簽名*。 可以在括號中指定最大位數
浮法(尺寸,d) 一個帶有浮點小數點的小數字。 可以在size參數中指定最大位數。 小數點右邊的最大位數在d參數中指定
雙(大小,d) 帶有小數點浮點的大數。 可以在size參數中指定最大位數。 小數點右邊的最大位數在d參數中指定
十進制(大小,d) 以字符串形式存儲的DOUBLE,允許使用固定的小數點。 可以在size參數中指定最大位數。 小數點右邊的最大位數在d參數中指定

日期數據類型: (Date data types:)

Data typeDescription
DATE()A date. Format: YYYY-MM-DD Note: The supported range is from ‘1000-01-01’ to ‘9999-12-31’
DATETIME()A date and time combination. Format: YYYY-MM-DD HH:MI:SS Note: The supported range is from ‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’
TIMESTAMP()A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch (‘1970-01-01 00:00:00’ UTC). Format: YYYY-MM-DD HH:MI:SS Note: The supported range is from ‘1970-01-01 00:00:01’ UTC to ‘2038-01-09 03:14:07’ UTC
TIME()A time. Format: HH:MI:SS Note: The supported range is from ‘-838:59:59’ to ‘838:59:59’
YEAR()A year in two-digit or four-digit format. Note: Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069
數據類型 描述
日期() 一個約會。 格式:YYYY-MM-DD注:支持的范圍是從“ 1000-01-01”到“ 9999-12-31”
約會時間() 日期和時間組合。 格式:YYYY-MM-DD HH:MI:SS注意:支持的范圍是從“ 1000-01-01 00:00:00”到“ 9999-12-31 23:59:59”
TIMESTAMP() 時間戳記。 TIMESTAMP值存儲為自Unix紀元('1970-01-01 00:00:00'UTC)以來的秒數。 格式:YYYY-MM-DD HH:MI:SS注意:支持的范圍是從UTC的“ 1970-01-01 00:00:01”到UTC的“ 2038-01-09 03:14:07”
時間() 一次 格式:HH:MI:SS注意:支持的范圍是'-838:59:59'到'838:59:59'
年() 兩位數字或四位數字格式的年份。 注意:允許以四位數字格式的值:1901到2155。允許以兩位數格式的值:70到69,表示從1970到2069的年份。

Finally, there are a few other data types that you will use:

最后,還有一些其他數據類型將要使用:

其他數據類型 (Other Data Types)

Data typeDescription
BOOLEANStores TRUE or FALSE values
ARRAYA set-length and ordered collection of elements
MULTISETA variable-length and unordered collection of elements
XMLStores XML data
數據類型 描述
BOOLEAN 存儲TRUEFALSE
ARRAY 元素的集合長度和有序集合
MULTISET 可變長度和無序元素集合
XML 存儲XML數據

翻譯自: https://www.freecodecamp.org/news/sql-data-types-mysql/

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390823.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390823.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390823.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

PHP7.2 redis

為什么80%的碼農都做不了架構師?>>> PHP7.2 的redis安裝方法: 順便說一下PHP7.2的安裝: wget http://cn2.php.net/distributions/php-7.2.4.tar.gz tar -zxvf php-7.2.4.tar.gz cd php-7.2.4./configure --prefix/usr/local/php…

leetcode 1787. 使所有區間的異或結果為零

題目 給你一個整數數組 nums??? 和一個整數 k????? 。區間 [left, right]&#xff08;left < right&#xff09;的 異或結果 是對下標位于 left 和 right&#xff08;包括 left 和 right &#xff09;之間所有元素進行 XOR 運算的結果&#xff1a;nums[left] XOR n…

【JavaScript】網站源碼防止被人另存為

1、禁示查看源代碼 從"查看"菜單下的"源文件"中同樣可以看到源代碼&#xff0c;下面我們就來解決這個問題&#xff1a; 其實這只要使用一個含有<frame></frame>標記的網頁便可以達到目的。 <frameset> <frame src"你要保密的文件…

梯度 cv2.sobel_TensorFlow 2.0中連續策略梯度的最小工作示例

梯度 cv2.sobelAt the root of all the sophisticated actor-critic algorithms that are designed and applied these days is the vanilla policy gradient algorithm, which essentially is an actor-only algorithm. Nowadays, the actor that learns the decision-making …

共享語義 unix語義_語義UI按鈕

共享語義 unix語義什么是語義UI按鈕&#xff1f; (What are Semantic UI Buttons?) A button indicates a possible user action. Semantic UI provides an easy-to-use syntax that simplifies not only the styling of a button, but also the natural language semantics.按…

垃圾回收算法優缺點對比

image.pngGC之前 說明&#xff1a;該文中的GC算法講解不僅僅局限于某種具體開發語言。 mutator mutator 是 Edsger Dijkstra 、 琢磨出來的詞&#xff0c;有“改變某物”的意思。說到要改變什么&#xff0c;那就是 GC 對象間的引用關系。不過光這么說可能大家還是不能理解&…

標準C程序設計七---77

Linux應用 編程深入 語言編程標準C程序設計七---經典C11程序設計 以下內容為閱讀&#xff1a; 《標準C程序設計》&#xff08;第7版&#xff09; 作者&#xff1a;E. Balagurusamy&#xff08;印&#xff09;&#xff0c; 李周芳譯 清華大學出版社…

leetcode 1190. 反轉每對括號間的子串

題目 給出一個字符串 s&#xff08;僅含有小寫英文字母和括號&#xff09;。 請你按照從括號內到外的順序&#xff0c;逐層反轉每對匹配括號中的字符串&#xff0c;并返回最終的結果。 注意&#xff0c;您的結果中 不應 包含任何括號。 示例 1&#xff1a; 輸入&#xff1a…

yolo人臉檢測數據集_自定義數據集上的Yolo-V5對象檢測

yolo人臉檢測數據集計算機視覺 (Computer Vision) Step by step instructions to train Yolo-v5 & do Inference(from ultralytics) to count the blood cells and localize them.循序漸進的說明來訓練Yolo-v5和進行推理(來自Ultralytics )以對血細胞進行計數并將其定位。 …

oauth2-server-php-docs 授權類型

授權碼 概觀 在Authorization Code交付式時使用的客戶端想要請求訪問受保護資源代表其他用戶&#xff08;即第三方&#xff09;。這是最常與OAuth關聯的授予類型。 詳細了解授權碼 用例 代表第三方來電履行 創建一個實例OAuth2\GrantType\AuthorizationCode并將其添加到您的服務…

flask框架視圖和路由_角度視圖,路由和NgModule的解釋

flask框架視圖和路由Angular vs AngularJS (Angular vs AngularJS) AngularJS (versions 1.x) is a JavaScript-based open source framework. It is cross platform and is used to develop Single Page Web Application (SPWA). AngularJS(版本1.x)是一個基于JavaScript的開源…

NGUI EventDelagate事件委托

using System.Collections; using System.Collections.Generic; using UnityEngine;public class BUttonClick : MonoBehaviour {public UIButton button_01;void Start(){if (button_01 null){Debug.Log("button組件丟失了");}else{//首先將腳本中的ClicktheButton…

leetcode 461. 漢明距離(位運算)

兩個整數之間的漢明距離指的是這兩個數字對應二進制位不同的位置的數目。 給出兩個整數 x 和 y&#xff0c;計算它們之間的漢明距離。 注意&#xff1a; 0 ≤ x, y < 231. 示例:輸入: x 1, y 4輸出: 2解釋: 1 (0 0 0 1) 4 (0 1 0 0)↑ ↑上面的箭頭指出了對應二進…

圖深度學習-第2部分

有關深層學習的FAU講義 (FAU LECTURE NOTES ON DEEP LEARNING) These are the lecture notes for FAU’s YouTube Lecture “Deep Learning”. This is a full transcript of the lecture video & matching slides. We hope, you enjoy this as much as the videos. Of cou…

Linux下 安裝Redis并配置服務

一、簡介 1、 Redis為單進程單線程模式&#xff0c;采用隊列模式將并發訪問變成串行訪問。 2、 Redis不僅僅支持簡單的k/v類型的數據&#xff0c;同時還提供list&#xff0c;set&#xff0c;zset&#xff0c;hash等數據結構的存儲。 3、 Redis支持數據的備份&#xff0c;即mas…

大omega記號_什么是大歐米茄符號?

大omega記號Similar to big O notation, big Omega(Ω) function is used in computer science to describe the performance or complexity of an algorithm.與大O表示法相似&#xff0c;大Omega(Ω)函數在計算機科學中用于描述算法的性能或復雜性。 If a running time is Ω…

leetcode 477. 漢明距離總和(位運算)

theme: healer-readable 題目 兩個整數的 漢明距離 指的是這兩個數字的二進制數對應位不同的數量。 計算一個數組中&#xff0c;任意兩個數之間漢明距離的總和。 示例: 輸入: 4, 14, 2 輸出: 6 解釋: 在二進制表示中&#xff0c;4表示為0100&#xff0c;14表示為1110&…

什么是跨域及跨域請求資源的方法?

1、由于瀏覽器同源策略&#xff0c;凡是發送請求url的協議、域名、端口三者之間任意一與當前頁面地址不同即為跨域。 2、跨域請求資源的方法&#xff1a; (1)、porxy代理(反向服務器代理) 首先將用戶發送的請求發送給中間的服務器&#xff0c;然后通過中間服務器再發送給后臺服…

量子信息與量子計算_量子計算為23美分。

量子信息與量子計算On Aug 13, 2020, AWS announced the General Availability of Amazon Braket. Braket is their fully managed quantum computing service. It is available on an on-demand basis, much like SageMaker. That means the everyday developer and data scie…

全面理解Java內存模型

Java內存模型即Java Memory Model&#xff0c;簡稱JMM。JMM定義了Java 虛擬機(JVM)在計算機內存(RAM)中的工作方式。JVM是整個計算機虛擬模型&#xff0c;所以JMM是隸屬于JVM的。 如果我們要想深入了解Java并發編程&#xff0c;就要先理解好Java內存模型。Java內存模型定義了多…