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 ><span >2<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">//</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">/</span>downloads<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">/</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">/</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">
将官网下载的解压包 解压到指定目录(例如 D:<span >//MysqL<span >-<span >5.7.<span >20<span >-<span >winx64)
<span >3<span >.添加环境变量【右键计算机】<span >--<span >》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【将MysqL的bin目录路径追加到变值值中,用 ; 分割】
<span >4<span >.初始化
<span >
C:\Program files (x86)\Parallels\Parallels Tools\Applications;d:\MysqL<span >-<span >5.7.<span >16<span >-<span >winx64\binMysqLd <span >--<span >initialize-insecure
<span >5<span >.启动MysqL服务
<span >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">-</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">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">127</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">. 无符号:</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">255</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 特别的: <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">1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">)构造。</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">int</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">(m)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">][</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">unsigned</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">][</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">zerofill</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">]</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 整数,数据类型用于保存一些范围的整数数值范围: 有符号: </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">2147483647</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 无符号:</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">4294967295</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">bigint</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">(m)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">][</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">unsigned</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">][</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">zerofill</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">]</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 大整数,数据类型用于保存一些范围的整数数值范围: 有符号:</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">9223372036854775807</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 无符号:</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">18446744073709551615</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">
作用:存储年龄,等级,ID,各种号码等
注意:为该类型指定宽度时,仅仅只是指定查询结果的显示宽度,与存储范围无关,所以我们使用默认的就可以了
有符号和无符号的最大数字需要的显示宽度均为10,
而针对有符号的最小值则需要11位才能显示完全,所以int类型默认的显示宽度为11是非常合理的
小数型:
准确的小数值,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"><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">[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">(M,D)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">]</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">UNSIGNED</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">]</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">ZEROFILL</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">]</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 单精度浮点数(非准确小数值),m是数字总个数,d是小数点后个数。 有符号:(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">3</span>.402823466E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">+</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">38</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">to</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">1</span>.175494351E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">1</span>.175494351E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">38</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">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">3</span>.402823466E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">+</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">38</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">) 无符号:</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">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">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">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">351</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">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">466</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">+</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">38</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">) </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">****</span> 数值越大,越不准确 <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">****</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">DOUBLE</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">(M,D)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">]</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">UNSIGNED</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">]</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">[</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">ZEROFILL</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">]</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 双精度浮点数(非准确小数值),m是数字总个数,d是小数点后个数。 有符号:(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">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">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">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">7</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">+</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">308</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">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">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">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">4</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">0</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">, (</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">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">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">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">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">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">4</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">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">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">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">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">7</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">+</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">308</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">) 无符号:</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">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">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">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">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">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">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">4</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">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">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">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">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">7</span> E<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">+</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">308</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">) </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">****</span> 数值越大,越不准确 <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">****</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">
作用:存储薪资、身高、体重、体质参数等
字符型:
<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">varchar</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">(m) </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">varchar</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 数据类型用于变长的字符串,可以包含最多达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">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">ab </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">,尾部的空格也会被存起来 强调:varchar类型会在真实数据前加1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">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"><</span>255bytes则需要1Bytes的前缀(1Bytes<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">=</span>8<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">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">2</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">**</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">8最大表示的数字为255) 如果真实的数据</span><span >></span>255bytes则需要2Bytes的前缀(2Bytes<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">=</span>16<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">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">2</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">**</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">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">%</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">。 因此,<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">text</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 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">2</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">**</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">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">1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">)个字符。
枚举类型(了解):
enum
An ENUM </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">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">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">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">535</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"><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">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">3000</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">.) 示例: </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">CREATE</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"><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">user</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> ( <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">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">40</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">),sex ENUM(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">男</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">女</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">未知</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">) ); </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">INSERT</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">INTO</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff00ff">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">VALUES</span> (<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">人1</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">男</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>),(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">人2</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">女</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">),(</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">人3</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">未知</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>),(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">人4</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">人妖</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">); PS:人4会插入成功吗??
集合类型(了解):
<span >set<span >
A </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">SET</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">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">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">64</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"><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"> members. 示例: </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">CREATE</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff"><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">SET</span>(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">a</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">b</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">c</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>,<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">d</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">)); </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">INSERT</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">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">VALUES</span> (<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">a,d</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>),(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">d,a</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span>),(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">a,d,a,d</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">);
日期<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">-</span>MM<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">1000</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">01</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">01</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">/</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">9999</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">12</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">31</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">)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">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">-838:59:59</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">/</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">838:59:59</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff0000">'</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #ff00ff">YEAR</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 年份值 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">1901</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">/</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">2155</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">DATETIME</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 混合<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">-</span>MM<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">1000</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">01</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">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">00</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">/</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">9999</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">12</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">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">59</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000">)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff">TIMESTAMP</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> <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">1970</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">01</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">-</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">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">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">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">00</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #808080">/</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">2037</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000"> 年某时)
作用:存储用户注册时间,文章发布时间,员工入职时间,出生时间,过期时间等
数据类型
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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)