[Statement]
Welcome to reprint, but please keep the original source → _ →
No. One Life: http://www.cnblogs.com/smyhvae/
Source: http://www.cnblogs.com/smyhvae/p/4028040.html
【text】
In the previous chapter, we learned to install MySQL software, since the software is installed, MySQL now officially began learning the basics of it, even zero-based, but also step by step. Well, the first thing to learn is the data type MySQL.
A data type:
- 1, integer (xxxint)
- 2, floating point (float and double)
- 3, fixed-point number (decimal)
- 4, character string (char, varchar, xxxtext)
- 5, binary data (xxxBlob)
- 6, the date and time type
Second, the data type description:
1, integer:
NOTE: M represents the maximum width of the display. Among them, the most int used.
2, floating point (float and Double ):
NOTE: The parameter only affects m display, does not affect the accuracy, d is different, it will affect accuracy.
3, fixed-point (decimal):
decimal (m, d) stored in fixed-point type float in the database are approximations, and the fixed-point type stored in the database the exact value. The parameter m is the maximum number of fixed-point numeric type (precision), the range from 0 to 65, d decimal point right number of digits, in the range of 0 to 30, but not more than m. Calculation of fixed-point accurate to 65 digits.
4, character string (char, varchar, xxxtext):
Note: If you want to save the text, you can use text. what
5, binary data (xxxBlob):
XXXBLOB和xxxtext是对应的,不过存储方式不同,xxxTEXT是以文本方式存储的,如果存储英文的话区会分大小写,而xxxBlob是以二进制方式存储的,不区分大小写。xxxBlob存储的数据只能整体读出。xxxTEXT可以指定字符集,xxxblob不用指定字符集。
例如,我们要存入一个图片文件,就可以将图片的二进制流存进来。因为只能整体读出,开销较大,读取较慢,所以在实际开发中用的较少。
6、日期时间类型:
timestamp(时间戳)比较特殊,如果定义一个字段的类型为timestamp,这个字段的时间会在其他字段修改的时候自动刷新。所以这个数据类型的字段可以存放这条记录最后被修改的时间,而不是真正来的存放时间。
datatime中的时间可以用字符串表示。注意,在数据库中,用单引号表示字符串。
三、数据类型的属性:
在定义数据类型时,可以同时定义一些属性。
其中,PRIMARY_KEY主键的含义:在定义数据库时,可以将某一列的字段定义为主键,来唯一代表这个数据库,这样的话,每一行记录都是唯一的。例如将学号定义主键,则每个人有唯一的id。一般用有含义的内容来定义主键不太好。
AUTO_INCREAMENT:自动递增。在主键中可以用这个属性。