MySQL:数据库入门篇1

MySQL:数据库入门篇1,第1张

概述1,什么是数据库?——存储数据的仓库数据库技术是计算机应用领域中非常重要的技术,它产生于20世纪60年代末,是数据管理的最新技术,也是软件技术的一个重要分支。简单的说,数据库就是一个存放数据的仓库,这个仓库是按照一定的数据结构(数据结构是指数据的组织形式或数据之间的联系)来组织、存储的,我们可以通过数据库提供的多种方法来管理数据库里的数据。更简单的形象理解,数据库和我们生活中存放杂物的仓库性质一样,区别只是存放的东西不同。2,什么是数据?——你所知道的都是数据存储在表中的信息就叫做数据3,什么是数据库表?数据表是关系数据库中一个非常重要的对象,是其它对象的基础,也是一系列二维数组的集合,用来存储、 *** 作数据的逻辑结构。根据信息的分类情况。一个数据库中可能包含若干个数据表,每张表是由行和列组成,记录一条数据,数据表就增加一行,每一列是由字段名和字段数据集合组成,列被称之为字段,每一列还有自己的多个属性,例如是否允许为空、默认值、长度、类型、存储编码、注释等4,数据库的组成:1)数据库服务器2)数据库管理系统3)库4)表5)记录6)数据数据库系统有3个主要的组成部分1.数据库(Database System):用于存储数据的地方。2.数据库管理系统(Database Management System,DBMS):用户管理数据库的软件。3.数据库应用程序(Database Application):为了提高数据库系统的处理能力所使用的管理数据库的软件补充。5,环境的安装MySQL下载地址:https://dev.mysql.com/downloads/installer/a:官网下载mysql安装程序b:安装mysql服务端c:安装mysql客户端d:客户端连接服务端e:通过客户端向服务器发送命令,执行对数据库文件的增删改差 *** 作。#1.下载:MySQL Community Server 5.7.20https://dev.mysql.com/downloads/mysql/#2.解压将官网下载的解压包 解压到指定目录(例如 D://mysql-5.7.20-winx64)#3.添加环境变量【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【将MySQL的bin目录路径追加到变值值中,用 ; 分割】C:Program Files (x86)ParallelsParallels ToolsApplications;d:mysql-5.7.16-winx64bin#4.初始化mysqld --initialize-insecure#5.启动mysql服务mysqld#6.连接mysql服务mysql -uroot -p 回车,有密码输入密码,没有继续回车安装 6,库 *** 作1)创建库CREATE DATABASE DB2 charset utf8;2)删除DROP DATABASE db2;3)使用(进入)use db14)查看库show databases ; -- 查看当前用户下所有的库名select DATABASE(); -- 查看当前使用的show CREATE DATABASE db1; -- 查看创建库的信息7,表 *** 作1)创建表create table info1(id int not null auto_increment PRIMARY key,name VARCHAR(50) not null,sex CHAR(2) NULL)2)查看表select * from info1; -- 查看表数据DESC info1; -- 查看表结构show create table info1; -- 查看表的创建信息3)删除表drop table info;4)修改表-- ALTER table info1 add age int not null ; -- 添加表字段-- alter table info1 drop age; -- 删除表字段-- alter table info1 modify name char(100) null ; -- 修改表字段属性-- alter table info1 CHANGE names name varchar(50) not null; -- 修改表名称补充信息alter table info1 add PRIMARY key(ID,names); -- 添加主键alter table info1 drop PRIMARY key ;-- 删除主键alter table info1 alter sex set default '男'; -- 设置默认值alter table info1 alter sex drop default; -- 删除默认值5)修改表名称rename  table info1 to info; -- 修改表名6)复制表1.CREATE table info3 select * from info where id =1;ps:主键自增/索引/触发器/外键 不会 被复制2.复制表结构CREATE table info5 SELECT * FROM info where 1!=1CREATE table info4 LIKE info;ps: 数据/触发器/外键 不会被复制8,数据类型MySQL支持多种类型,大致可以分为四类:数值、字符串类型、日期/时间和其他类型。二进制类型:bit[(M)]二进制位(101001),m表示二进制位的长度(1-64),默认m=1整数类型:tinyint[(m)] [unsigned] [zerofill]小整数,数据类型用于保存一些范围的整数数值范围:有符号:-128 ~ 127.无符号:255特别的: MySQL中无布尔值,使用tinyint(1)构造。int[(m)][unsigned][zerofill]整数,数据类型用于保存一些范围的整数数值范围:有符号: -2147483648 ~ 2147483647无符号:4294967295bigint[(m)][unsigned][zerofill]大整数,数据类型用于保存一些范围的整数数值范围:有符号:-9223372036854775808 ~ 9223372036854775807无符号:18446744073709551615作用:存储年龄,等级,id,各种号码等注意:为该类型指定宽度时,仅仅只是指定查询结果的显示宽度,与存储范围无关,所以我们使用默认的就可以了有符号和无符号的最大数字需要的显示宽度均为10,而针对有符号的最小值则需要11位才能显示完全,所以int类型默认的显示宽度为11是非常合理的小数型:decimal[(m[,d])] [unsigned] [zerofill]准确的小数值,m是数字总个数(负号不算),d是小数点后个数。 m最大值为65,d最大值为30。特别的:对于精确数值计算时需要用此类型decaimal能够存储精确值的原因在于其内部按照字符串存储。FLOAT[(M,D)] [UNSIGNED] [ZEROFILL]单精度浮点数(非准确小数值),m是数字总个数,d是小数点后个数。有符号:(-3.402823466E+38 to -1.175494351E-38),0,(1.175494351E-38 to 3.402823466E+38)无符号:0,(1.175 494 351 E-38,3.402 823 466 E+38)**** 数值越大,越不准确 ****DOUBLE[(M,D)] [UNSIGNED] [ZEROFILL]双精度浮点数(非准确小数值),m是数字总个数,d是小数点后个数。有符号:(-1.797 693 134 862 315 7 E+308,-2.225 073 858 507 201 4 E-308),0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308)无符号:0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308)**** 数值越大,越不准确 ****作用:存储薪资、身高、体重、体质参数等字符型:char (m)char数据类型用于表示固定长度的字符串,可以包含最多达255个字符。其中m代表字符串的长度。PS: 即使数据小于m长度,也会占用m长度,但是在查询时,查出的结果会自动删除尾部的空格特点:定长,简单粗暴,浪费空间,存取速度快varchar(m)varchar 数据类型用于变长的字符串,可以包含最多达65535个字符(理论上可以,但是实际上在超出21845长度后,mysql会自动帮您转换数据类型为文本类型)。其中m代表该数据类型所允许保存的字符串的最大长度,只要长度小于该最大值的字符串都可以被保存在该数据类型中。PS: varchar类型存储数据的真实内容,例如:如果'ab ',尾部的空格也会被存起来强调:varchar类型会在真实数据前加1-2Bytes的前缀,该前缀用来表示真实数据的bytes字节数(1-2Bytes最大表示65535个数字,正好符合mysql对row的最大字节限制,即已经足够使用)如果真实的数据<255bytes则需要1Bytes的前缀(1Bytes=8bit 2**8最大表示的数字为255)如果真实的数据>255bytes则需要2Bytes的前缀(2Bytes=16bit 2**16最大表示的数字为65535)特点:变长,精准,节省空间,存取速度慢sql优化:创建表时,定长的类型往前放,变长的往后放比如性别 比如地址或描述信息PS:虽然varchar使用起来较为灵活,但是从整个系统的性能角度来说,char数据类型的处理速度更快,有时甚至可以超出varchar处理速度的50%。因此,用户在设计数据库时应当综合考虑各方面的因素,以求达到最佳的平衡texttext数据类型用于保存变长的大字符串,可以最多到65535 (2**16 − 1)个字符。枚举类型(了解):enumAn ENUM column can have a maximum of 65,535 distinct elements. (The practical limit is less than 3000.)示例:CREATE TABLE user (name VARCHAR(40),sex ENUM('男', '女', '未知'));INSERT INTO user (name, sex) VALUES ('人1','男'), ('人2','女'),('人3','未知'),('人4','人妖');PS:人4会插入成功吗??集合类型(了解):setA SET column can have a maximum of 64 distinct members.示例:CREATE TABLE myset (col SET('a', 'b', 'c', 'd'));INSERT INTO myset (col) VALUES ('a,d'), ('d,a'), ('a,d,a'), ('a,d,d'), ('d,a,d');日期/时间类型:DATE 日期值YYYY-MM-DD(1000-01-01/9999-12-31)TIME 时间值或持续时间HH:MM:SS('-838:59:59'/'838:59:59')YEAR 年份值YYYY(1901/2155)DATETIME 混合日期和时间值YYYY-MM-DD HH:MM:SS(1000-01-01 00:00:00/9999-12-3

1,什么是数据库?——存储数据的仓库

  数据库技术是计算机应用领域中非常重要的技术,它产生于20世纪60年代末,是数据管理的最新技术,也是软件技术的一个重要分支。

  简单的说,数据库就是一个存放数据的仓库,这个仓库是按照一定的数据结构(数据结构是指数据的组织形式或数据之间的联系)来组织、存储的,我们可以通过数据库提供的多种方法来管理数据库里的数据。更简单的形象理解,数据库和我们生活中存放杂物的仓库性质一样,区别只是存放的东西不同。

2,什么是数据?——你所知道的都是数据

  存储在表中的信息就叫做数据

3,什么是数据库表? 

4,数据库的组成:

  1)数据库服务器

  2)数据库管理系统

  3)库

  4)表

  5)记录

  6)数据

   数据库系统有3个主要的组成部分

   1.数据库(Database System):用于存储数据的地方。

   2.数据库管理系统(Database Management System,DBMS):用户管理数据库的软件。

   3.数据库应用程序(Database Application):为了提高数据库系统的处理能力所使用的管理数据库的软件补充。

5,环境的安装

  MysqL下载地址:https://dev.MysqL.com/downloads/installer/

<span >1.下载:MysqL Community Server <span >5.7.<span >20<span >
<a href="https://m.jb51.cc/tag/http/" target="_blank" >http</a>s:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;//</span>dev.<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" >MysqL</a>.com<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;/</span>downloads<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;/</span><a href="https://www.jb51.cc/tag/MysqL/" target="_blank" >MysqL</a><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;/</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;
<span >2<span >.解压

将官网下载的解压包 解压到指定目录(例如 D:<span >//MysqL<span >-<span >5.7.<span >20<span >-<span >winx64)

<span >3<span >.添加环境变量

【右键计算机】<span >--<span >》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【将MysqL的bin目录路径追加到变值值中,用 ; 分割】
<span >
C:\Program files (x86)\Parallels\Parallels Tools\Applications;d:\MysqL<span >-<span >5.7.<span >16<span >-<span >winx64\bin

<span >4<span >.初始化

MysqLd <span >--<span >initialize-insecure
<span >

<span >5<span >.启动MysqL服务

MysqLd

<span >6<span >.连接MysqL服务

MysqL <span >-uroot <span >-p 回车,有密码输入密码,没有继续回车

6,库 *** 作

  1)创建库

  CREATE DATABASE DB2 charset utf8;

  2)删除

  DROP DATABASE db2;

  3)使用(进入)

  use db1

  4)查看库  

  show databases ; -- 查看当前用户下所有的库名   select DATABASE(); -- 查看当前使用的   show CREATE DATABASE db1; -- 查看创建库的信息

7,表 *** 作

  1)创建表 

  create table info1(     ID int not null auto_increment PRIMARY key,     name VARCHAR(50) not null,     sex CHAR(2) NulL     )

  2)查看表  

  select * from info1; -- 查看表数据

  DESC info1; -- 查看表结构

  show create table info1; -- 查看表的创建信息

  3)删除表

  drop table info;

  4)修改表 

  -- ALTER table info1 add age int not null ; -- 添加表字段

  -- alter table info1 drop age; -- 删除表字段

  -- alter table info1 modify name char(100) null ; -- 修改表字段属性

  -- alter table info1 CHANGE names name varchar(50) not null; -- 修改表名称   补充信息   alter table info1 add PRIMARY key(ID,names); -- 添加主键

  alter table info1 drop PRIMARY key ;-- 删除主键   alter table info1 alter sex set default '男'; -- 设置默认值

  alter table info1 alter sex drop default; -- 删除默认值

  5)修改表名称

  rename  table info1 to info; -- 修改表名

  6)复制表  

  1.CREATE table info3 select * from info where ID =1;   ps:主键自增/索引/触发器/外键 不会 被复制   2.复制表结构   CREATE table info5 SELECT * FROM info where 1!=1

  CREATE table info4 like info;   ps: 数据/触发器/外键 不会被复制

8,数据类型

MysqL支持多种类型,大致可以分为四类:数值、字符串类型、日期/时间和其他类型。

),m表示二进制位的长度(),默认m=整数类型:
<span >tinyint
<span >[
<span >(m)
<span >]
<span >[
<span >unsigned
<span >]
<span >[
<span >zerofill
<span >]
<span >

    小整数,数据类型用于保存一些范围的整数数值范围:    有符号:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;128</span> ~ <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;127</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;.    无符号:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;255</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;    特别的: <a href="https://www.jb51.cc/tag/MysqL/" target="_blank" >MysqL</a>中无布尔值,<a href="https://m.jb51.cc/tag/shiyong/" target="_blank" >使用</a><a href="https://www.jb51.cc/tag/tinyint/" target="_blank" >tinyint</a>(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)构造。</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;int</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;(m)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;][</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;unsigned</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;][</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;zerofill</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;]</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;    整数,数据类型用于保存一些范围的整数数值范围:    有符号: </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2147483648</span> ~ <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2147483647</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;    无符号:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;4294967295</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;bigint</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;(m)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;][</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;unsigned</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;][</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;zerofill</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;]</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;    大整数,数据类型用于保存一些范围的整数数值范围:    有符号:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;9223372036854775808</span> ~ <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;9223372036854775807</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;    无符号:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;18446744073709551615</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;

作用:存储年龄,等级,ID,各种号码等

注意:为该类型指定宽度时,仅仅只是指定查询结果的显示宽度,与存储范围无关,所以我们使用默认的就可以了
有符号和无符号的最大数字需要的显示宽度均为10,
而针对有符号的最小值则需要11位才能显示完全,所以int类型默认的显示宽度为11是非常合理的

小数型:
<span >decimal<span >[<span >(m[,d<span >])] <span >[<span >unsigned<span >] <span >[<span >zerofill<span >]<span >
准确的小数值,m是数字总个数(负号不算),d是小数点后个数。 m最大值为65,d最大值为30。

    特别的:对于精确数值计算时需要用此类型    dec<a href="https://www.jb51.cc/tag/aim/" target="_blank" >aim</a>al能够存储精确值的原因在于其内部按照字符串存储。</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;<a href="https://m.jb51.cc/tag/float/" target="_blank" >float</a></span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;(M,D)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;]</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;UNSIGNED</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;]</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;ZEROFILL</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;]</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;    单精度浮点数(非准确小数值),m是数字总个数,d是小数点后个数。    有符号:(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;3</span>.402823466E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;+</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;38</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;to</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1</span>.175494351E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;38</span>),<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;0</span>,(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1</span>.175494351E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;38</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;to</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;3</span>.402823466E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;+</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;38</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)    无符号:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;0</span>,(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1.175</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;494</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;351</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;38</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;3.402</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;823</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;466</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;+</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;38</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)    </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;****</span> 数值越大,越不准确 <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;****</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;DOUBLE</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;(M,D)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;]</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;UNSIGNED</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;]</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;ZEROFILL</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;]</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;    双精度浮点数(非准确小数值),m是数字总个数,d是小数点后个数。    有符号:(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1.797</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;693</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;134</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;862</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;315</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;7</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;+</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;308</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2.225</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;073</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;858</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;507</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;201</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;4</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;308</span>),<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;0</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;,           (</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2.225</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;073</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;858</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;507</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;201</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;4</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;308</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1.797</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;693</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;134</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;862</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;315</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;7</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;+</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;308</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)    无符号:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;0</span>,(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2.225</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;073</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;858</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;507</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;201</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;4</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;308</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1.797</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;693</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;134</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;862</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;315</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;7</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;+</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;308</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)    </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;****</span> 数值越大,越不准确 <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;****</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;

作用:存储薪资、身高、体重、体质参数等

字符型:
<span >char<span > (m)
char数据类型用于表示固定长度的字符串,可以包含最多达255个字符。其中m代表字符串的长度。

    PS: 即使数据小于m长度,也会占用m长度,但是在<a href="https://www.jb51.cc/tag/chaxun/" target="_blank" >查询</a>时,查出的结果会<a href="https://www.jb51.cc/tag/zidong/" target="_blank" >自动</a><a href="https://www.jb51.cc/tag/shanchu/" target="_blank" >删除</a>尾部的空格    <a href="https://m.jb51.cc/tag/tedian/" target="_blank" >特点</a>:定长,简单粗暴,浪费空间,存取速度快</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;varchar</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;(m)    </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;varchar</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt; 数据类型用于变长的字符串,可以包含最多达65535个字符(理论上可以,但是实际上在<a href="https://m.jb51.cc/tag/chaochu/" target="_blank" >超出</a>21845长度后,<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" >MysqL</a>会<a href="https://www.jb51.cc/tag/zidong/" target="_blank" >自动</a>帮您转换数据类型为文本类型)。    其中m代表该数据类型所允许保存的字符串的最大长度,只要长度小于该最大值的字符串都可以被保存在该数据类型中。    PS: varchar类型存储数据的真实<a href="https://www.jb51.cc/tag/neirong/" target="_blank" >内容</a>,例如:如果</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;ab  </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;,尾部的空格也会被存起来    强调:varchar类型会在真实数据前加1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span>2Bytes的前缀,该前缀用来表示真实数据的bytes字节数(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;2Bytes最大表示65535个数字,正好符合<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" >MysqL</a>对row的最大字节限制,即已经足够<a href="https://m.jb51.cc/tag/shiyong/" target="_blank" >使用</a>)    如果真实的数据</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;<</span>255bytes则需要1Bytes的前缀(1Bytes<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;=</span>8<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;bit</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;**</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;8最大表示的数字为255)    如果真实的数据</span><span &gt;></span>255bytes则需要2Bytes的前缀(2Bytes<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;=</span>16<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;bit</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;**</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;16最大表示的数字为65535)    <a href="https://m.jb51.cc/tag/tedian/" target="_blank" >特点</a>:变长,精准,节省空间,存取速度慢    <a href="https://www.jb51.cc/tag/sql/" target="_blank" >sql</a>优化:<a href="https://m.jb51.cc/tag/chuangjian/" target="_blank" >创建</a>表时,定长的类型往前放,变长的往后放                    比如性别          比如<a href="https://m.jb51.cc/tag/dizhi/" target="_blank" >地址</a>或描述信息    PS:虽然varchar<a href="https://m.jb51.cc/tag/shiyong/" target="_blank" >使用</a>起来较为灵活,但是从整个<a href="https://m.jb51.cc/tag/xitong/" target="_blank" >系统</a>的<a href="https://www.jb51.cc/tag/xingneng/" target="_blank" >性能</a>角度来说,char数据类型的处理速度更快,有时甚至可以<a href="https://m.jb51.cc/tag/chaochu/" target="_blank" >超出</a>varchar处理速度的50</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;%</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;。        因此,<a href="https://www.jb51.cc/tag/yonghu/" target="_blank" >用户</a>在设计<a href="https://www.jb51.cc/tag/shujuku/" target="_blank" >数据库</a>时应当综合考虑各方面的因素,以求达到最佳的平衡            </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;text</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;    text数据类型用于保存变长的大字符串,可以最多到65535 (</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;**</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;16</span> − <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)个字符。

枚举类型(了解):
enum

    An ENUM </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;c<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>umn</span> can have a maximum <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;of</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;65</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;535</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;<a href="https://www.jb51.cc/tag/dis/" target="_blank" >dis</a>tinct</span> elements. (The practical <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>mit <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;is</span> less than <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;3000</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;.)    示例:        </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;CREATE</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;<a href="https://m.jb51.cc/tag/table/" target="_blank" >table</a></span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff00ff"&gt;user</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt; (         <a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a> </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;VARCHAR</span>(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;40</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;),sex ENUM(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;男</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;女</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;未知</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)        );        </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;INSERT</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;INTO</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff00ff"&gt;user</span> (<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a>,sex) <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;VALUES</span> (<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;人1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;男</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>),(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;人2</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;女</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;),(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;人3</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;未知</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>),(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;人4</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;人妖</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;);        PS:人4会插入成功吗??        

集合类型(了解):
<span >set<span >

    A </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;SET</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;c<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>umn</span> can have a maximum <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;of</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;64</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;<a href="https://www.jb51.cc/tag/dis/" target="_blank" >dis</a>tinct</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt; members.    示例:    </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;CREATE</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;<a href="https://m.jb51.cc/tag/table/" target="_blank" >table</a></span> myset (c<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;SET</span>(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;a</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;b</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;c</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;d</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;));    </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;INSERT</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;INTO</span> myset (c<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>) <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;VALUES</span> (<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;a,d</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>),(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;d,a</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span>),(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;a,d,a,d</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;);

日期<span >/<span >时间类型:

DATE     <a href="https://m.jb51.cc/tag/riqi/" target="_blank" >日期</a>值    YYYY</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span>MM<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span>DD(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1000</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;01</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;01</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;/</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;9999</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;12</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;31</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)TIME  <a href="https://m.jb51.cc/tag/shijian/" target="_blank" >时间</a>值或持续<a href="https://m.jb51.cc/tag/shijian/" target="_blank" >时间</a>    HH:MM:SS(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;-838:59:59</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;/</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;838:59:59</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000"&gt;'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff00ff"&gt;YEAR</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt; 年份值    YYYY(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1901</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;/</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2155</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;DATETIME</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt; 混合<a href="https://m.jb51.cc/tag/riqi/" target="_blank" >日期</a>和<a href="https://m.jb51.cc/tag/shijian/" target="_blank" >时间</a>值    YYYY</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span>MM<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span>DD HH:MM:SS(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1000</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;01</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;01</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;00</span>:<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;00</span>:<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;00</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;/</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;9999</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;12</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;31</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;23</span>:<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;59</span>:<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;59</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt;)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"&gt;TIMESTAMP</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt; <a href="https://m.jb51.cc/tag/shijian/" target="_blank" >时间</a>戳    YYYYMMDD HHMMSS(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;1970</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;01</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;01</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;00</span>:<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;00</span>:<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;00</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080"&gt;/</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000; <a href="https://m.jb51.cc/tag/Font/" target="_blank" >Font</a>-weight: b<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>d"&gt;2037</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"&gt; 年某时)

作用:存储用户注册时间,文章发布时间,员工入职时间,出生时间,过期时间等

数据类型

9.数据 *** 作   1。增   -- INSERT into info values(1,'韩涉','女');

  -- INSERT into info(ID,nameS) values(2,'韩涉');

  -- INSERT into info(ID,nameS) values(3,'韩涉'),(4,(5,'韩涉');

  -- INSERT into info(names,sex) select nameS,sex from info ;   2。删   -- DELETE from info where ID = '11'; -- 删除指定数据   -- delete from info; -- 删除整张表中所有的数据   TruncATE info; -- 清空整张表   3.改   update info set sex = '人妖',names = '韩小强' where ID=12;   4.查

    4.1 简单查询       select * from person; -- 查询所有

      select name,SEX from person; -- 按指定字段查询

      select name,SEX as'性别' from person; -- as 表示为字段起别名

      select salary+200 from person; -- 可以进行数据列运算

      select disTINCT age,name FROM person; -- 去重复查询

    4.2 条件查询       1.运算符         select * FROM person WHERE age >20;         select * FROM person WHERE age <=20;

        select * FROM person WHERE age <>20;         select * FROM person WHERE age !=20;

      2.null 关键字         select * FROM person where dept_ID is null;

        select * FROM person where dept_ID is not null;

        select * FROM person where name ='';

      3.逻辑运算符 and or

        select * from person where age = 28 and salary =53000;

        select * from person where age = 23 or salary =2000;         select * from person where not(age = 28 and salary =53000);

    4.3 区间查询     select * from person where age BETWEEN 18 and 20;

    ps: between...and 前后包含所指定的值     等价于 select * from person where salary >= 4000 and salary <= 8000;

    4.4集合查询     select * from person where ID = 1 or ID = 3 or ID = 5;

    select * from person where ID not in(1,3,5);

    4.5 模糊查询

    select * from person where name like '%e%'; -- 包含指定参数     select * from person where name like '%e'; -- 以什么结尾     select * from person where name like 'e%'; -- 以什么开头

    select * from person where name like '__e%'; -- _表示单个字符站位符

    select * from person where name like '__';     4.6 排序查询     select * from person where age >30 ORDER BY salary desc; -- ASC正序 DESC倒序     select * from person ORDER BY CONVERT(name USING gbk);-- 中文排序

  

总结

以上是内存溢出为你收集整理的MySQL:数据库入门篇1全部内容,希望文章能够帮你解决MySQL:数据库入门篇1所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1169202.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存