网站建设课程内容网站的用户体验怎么做

当前位置: 首页 > news >正文

网站建设课程内容,网站的用户体验怎么做,招聘做网站,网络广告效果评估文章目录1.数据类型1.1数据类型分类1.2数值类型1.2.1tinyint类型1.2.2bit类型1.2.3小数类型1.2.3.1 float1.2.3.2 decimal1.3字符串类型1.3.1 char1.3.2 varchar1.3.3char和varchar的比较1.4日期和时间类型1.5 enum和set1.5.1 enum1.5.2 set1.5.3 示例1.数据类型 1.1数据类型分… 文章目录1.数据类型1.1数据类型分类1.2数值类型1.2.1tinyint类型1.2.2bit类型1.2.3小数类型1.2.3.1 float1.2.3.2 decimal1.3字符串类型1.3.1 char1.3.2 varchar1.3.3char和varchar的比较1.4日期和时间类型1.5 enum和set1.5.1 enum1.5.2 set1.5.3 示例1.数据类型 1.1数据类型分类 图1.1-1
1.2数值类型 图1.2-1
1.2.1tinyint类型 数值越界测试 mysql create table t1 - (id tinyint);

Query OK, 0 rows affected (0.17 sec)mysql desc t1;

| Field | Type | Null | Key | Default | Extra |

| id | tinyint(4) | YES | | NULL | |

1 row in set (0.01 sec)mysql insert into t1 values (1); Query OK, 1 row affected (0.03 sec)mysql insert into t1 values (128); ERROR 1264 (22003): Out of range value for column id at row 1 mysql insert into t1 values (127); Query OK, 1 row affected (0.05 sec)mysql insert into t1 values (-127); Query OK, 1 row affected (0.02 sec)mysql insert into t1 values (-128); Query OK, 1 row affected (0.03 sec)mysql insert into t1 values (-129); ERROR 1264 (22003): Out of range value for column id at row 1

mysql select * from t1;

id
1
127
-127
-128

4 rows in set (0.00 sec) 说明 在MySQL中整形可以指定具有符号的和无符号的默认是有符号的。 可以通过UNSIGNED来说明某个字段是无符号的。 无符号案例 mysql create table t2(id tinyint unsigned); Query OK, 0 rows affected (0.26 sec)mysql insert into t2 values (0); Query OK, 1 row affected (0.03 sec)mysql insert into t2 values (-1); ERROR 1264 (22003): Out of range value for column id at row 1 mysql insert into t2 values (1); Query OK, 1 row affected (0.03 sec)mysql insert into t2 values (255); Query OK, 1 row affected (0.04 sec)mysql insert into t2 values (256); ERROR 1264 (22003): Out of range value for column id at row 1

mysql select * from t1;

id
1
127
-127
-128

4 rows in set (0.01 sec)mysql desc t1;

| Field | Type | Null | Key | Default | Extra |

| id | tinyint(4) | YES | | NULL | |

1 row in set (0.02 sec)其他类型自己推导 注意尽量不适用unsigned对于int类型可能存在放不下的数据int unsigned同样可以存放不下与其如此还不如设计时讲int类型提升为bigint类型。 1.2.2bit类型 基本语法 bit[(M)]位字段类型。M表示每个值的位数范围从1到64。如果M被忽略默认为1。 示例 mysql create table t3(id int,a bit(8));

Query OK, 0 rows affected (0.21 sec)mysql desc t3;

| Field | Type | Null | Key | Default | Extra |

| id | int(11) | YES | | NULL | |

| a | bit(8) | YES | | NULL | |

2 rows in set (0.00 sec)mysql insert into t3 values (1,10);

Query OK, 1 row affected (0.03 sec)mysql select * from t3;

| id | a |

| 1 | |

1 row in set (0.00 sec)发现很奇怪的现象a的数据10没有出现 bit使用的注意事项 bit字段在显示时是按照ASCII码对应的值显示。 mysql insert into t3 values(65,65);

Query OK, 1 row affected (0.02 sec)mysql select * from t3;

| id | a |

| 1 | |

| 65 | A |

2 rows in set (0.00 sec) 如果我们有这样的值只存放0或者1这时候可以定义为bit(1)。这样可以节省空间 mysql create table t4(- gender bit(1)); Query OK, 0 rows affected (0.21 sec)mysql insert into t4 values (1); Query OK, 1 row affected (0.02 sec)mysql insert into t4 values (0); Query OK, 1 row affected (0.03 sec)mysql insert into t4 values (2); –当插入2时,已经越界了 ERROR 1406 (22001): Data too long for column gender at row 11.2.3小数类型 1.2.3.1 float 语法 float[(m,d)] [unsigned] : M指定显示长度,d指定小数位数m,占用空间4个字节 示例 小数:float(4,2) :表示一共最多可以有4位长度,其中小数点后两位,意味着小数点前最多2位,即数据范围为 -99.99~99.99,MySQL在保存值时会进行四舍五入. mysql create table t5(num float(4,2)); Query OK, 0 rows affected (0.26 sec)mysql insert into t5 values (-99.99); Query OK, 1 row affected (0.03 sec)mysql insert into t5 values (99.99); Query OK, 1 row affected (0.04 sec)mysql insert into t5 values (99.991);

Query OK, 1 row affected (0.04 sec)mysql select * from t5;

num
-99.99
99.99
99.99

3 rows in set (0.01 sec)mysql insert into t5 values (99.995); ERROR 1264 (22003): Out of range value for column num at row 1 mysql insert into t5 values (-99.994);

Query OK, 1 row affected (0.04 sec)mysql select * from t5;

num
-99.99
99.99
99.99
-99.99

4 rows in set (0.01 sec)注意当我们的float(4,2)如果是一个有符号的,则表示范围是(-99.99,99.99),如果是无符号的,范围会变成(0,99.99) 示例 mysql create table t6(num float(4,2) unsigned); Query OK, 0 rows affected (0.06 sec)mysql insert into t6 values(0); Query OK, 1 row affected (0.04 sec)mysql insert into t6 values(99.99); Query OK, 1 row affected (0.03 sec)mysql insert into t6 values(-0); Query OK, 1 row affected (0.03 sec)mysql insert into t6 values(-1); ERROR 1264 (22003): Out of range value for column num at row 1

mysql select * from t6;

num
0.00
99.99
0.00

3 rows in set (0.00 sec)1.2.3.2 decimal 语法 decimal(m,d)[unsigned] : 定点数m指定长度,d表示小数点的位数 decimal(5,2)表示范围是-999.99~999.99 decimal(5,2)unsigned表示的范围0~999.99 decimal和float很像,但是有区别 float和decimal表示的精度不一样 – decimal精度更高更准确 mysql create table t7(num1 float(10,8),num2 decimal(10,8));

Query OK, 0 rows affected (0.56 sec)mysql desc t7;

| Field | Type | Null | Key | Default | Extra |

| num1 | float(10,8) | YES | | NULL | |

| num2 | decimal(10,8) | YES | | NULL | |

2 rows in set (0.01 sec)mysql insert into t7 values(23.12345612,23.12345612);

Query OK, 1 row affected (0.04 sec)mysql select * from t7; – 发现decimal的精度更准确因此我们希望数据高精度选择decimal

| num1 | num2 |

| 23.12345695 | 23.12345612 |

1 row in set (0.00 sec)说明float表示的精度大约是7位 decimal整数最大位数m为65。支持小数最大位数d是30。如果d被省略默认为0。如果m被省略默认为10。 建议如果希望小数的精度高推荐使用decimal。 1.3字符串类型 1.3.1 char 语法 char(L) : 固定长度字符串L是可以存储的长度,单位为字符,最大长度值可以为255 示例 mysql create table t8 (name char(2)); Query OK, 0 rows affected (0.19 sec)mysql insert into t8 values(ab); Query OK, 1 row affected (0.04 sec)mysql insert into t8 values(语言);

Query OK, 1 row affected (0.03 sec)mysql select * from t8;

name
ab
语言

2 rows in set (0.00 sec)说明char(2)表示可以存放两个字符可以是字母或者汉字但是不能超过2个。L的最大值只能是255 mysql create table t9 (name char(256)); ERROR 1074 (42000): Column length too big for column name (max 255); use BLOB or TEXT instead1.3.2 varchar 语法 varchar(L) : 可变长度字符串,L表示字符长度,最大长度65535个字节 示例 mysql create table tt1(name varchar(6)); – 表示可以存放6个字符

Query OK, 0 rows affected (0.23 sec)mysql desc tt1;

| Field | Type | Null | Key | Default | Extra |

| name | varchar(6) | YES | | NULL | |

1 row in set (0.00 sec)mysql insert into tt1 values (hello); Query OK, 1 row affected (0.04 sec)mysql insert into tt1 values (我爱你,祖国); Query OK, 1 row affected (0.02 sec)mysql insert into tt1 values (我很爱你,祖国); ERROR 1406 (22001): Data too long for column name at row 1

mysql select * from tt1;

name
hello
我爱你,祖国

2 rows in set (0.00 sec)说明 关于varchar(len),len到底是多大,这个len值和表的编码密切相关 varchar长度可以指定为0到65535之间的值但是有1-3个字节用于记录数据大小所以说有效字节数是65535。当我们的表的编码是utf8时,varchar(n)的参数n的最大值为65535/321844(因为utf中,一个字符占3个字节)如果编码是gbk,varchar(n)的参数n的最大值为65536/232766(因为gbk一个字符占2个字节) mysql create table tt2(name varchar(21845))charsetutf8; – 验证utf8确实不能超过21844 ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs mysql create table tt2(name varchar(21844))charsetutf8; Query OK, 0 rows affected (0.21 sec)mysql create table tt3(name varchar(32767))charsetgbk; – 验证gbk确实不能超过32766 ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs mysql create table tt3(name varchar(32766))charsetgbk; Query OK, 0 rows affected (0.24 sec)1.3.3char和varchar的比较 实际存储char(4)varcahr(4)char占用字节varchar占用字节abcdabcdabcd4*3124*3113AAA4*3121*314AbcdeXX数据超过长度数据超过长度 如何选择定长或变长字符串 如果数据确定长度都一样就是用定长char比如身份证手机号等如果数据长度有变化就是用变长varchar比如名字地址但是你要保证最长的能存进去定长的磁盘空间比较浪费但是效率高变长的磁盘空间比较节省但是效率低定长的意义是直接开辟好对应的空间变长的意义是在不超过自定义范围的情况下用多少开辟多少。 1.4日期和时间类型 常用的日期有如下三个 data 日期 yyyy-mm-dd占三个字节datetime : 时间日期格式yyyy-mm-dd HH:ii:ss表示范围从1000到9999占用8字节timestamp : 时间辍(格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数) 格式: yyyy-mm-dd HH:ii:ss 和datetime完全一致占用四字节。 示例 mysql create table tt3(t1 date,t2 datetime,d3 timestamp); ERROR 1050 (42S01): Table tt3 already exists mysql create table tt4(t1 date,t2 datetime,d3 timestamp); Query OK, 0 rows affected (0.17 sec)mysql insert into tt4 (t1,t2) values(2023-04-11,1999-7-1 8:0:0);

Query OK, 1 row affected (0.03 sec)mysql select * from tt4;

| t1 | t2 | d3 |

| 2023-04-11 | 1999-07-01 08:00:00 | 2023-04-11 20:58:24 |

1 row in set (0.01 sec)我们可以看到添加数据时时间戳自动补上当前时间。这是因为d3有默认值。我们可以查看一下tt4的表结构. mysql desc tt4;

| Field | Type | Null | Key | Default | Extra |

| t1 | date | YES | | NULL | | | t2 | datetime | YES | | NULL | |

| d3 | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |

3 rows in set (0.01 sec)我们如果更新t1的时间表中又会有什么变化 mysql select * from tt4;

| t1 | t2 | d3 |

| 2023-04-11 | 1999-07-01 08:00:00 | 2023-04-11 20:58:24 |

1 row in set (0.01 sec) mysql update tt4 set t12000-1-1; Query OK, 1 row affected (0.03 sec)

Rows matched: 1 Changed: 1 Warnings: 0mysql select * from tt4;

| t1 | t2 | d3 |

| 2000-01-01 | 1999-07-01 08:00:00 | 2023-04-11 21:00:44 |

1 row in set (0.00 sec)我们发现更新数据时时间戳会更新成当前时间。 1.5 enum和set 1.5.1 enum 语法 enum枚举单选类型 enum(选项1,选项2,选项3…..); 该设定值只是提供了若干个选项的值最终一个单元格中实际值存储了其中一个值而是处于效率考虑这些值实际存储的是 数字因为这些选项的每个选项值一次对应如下数字1,2,3,…..最多65535个当我们添加枚举值时也可以添加对应的数字编号。 1.5.2 set 语法 set集合多选类型 set(选项值1,选项值2,选项值3,……); 该设定值只是提供了若干个选项的值最终一个单元格中设计可以存储了其中任意多个值而且处于效率考虑这些值实际存储的是 位图数字因为这些选项的每个选项值依次对应如下数字1,2,4,8,16,32…..最多64个 示例set(选项1,选项2,选项3,选项4,选项5); 选项1选项2选项3选项4选项50000100010001000100010000 因此如果你要同时选择选项1和选项2可以输入3 因为00001 00010 00011对应的10进制数字3 说明不建议在添加枚举值集合值的时候采用数字的方式因为不利于阅读 1.5.3 示例 示例 有一个调查表votes需要调查人的喜好比如(登山,游泳,篮球,武术)中去选择(可以多选)性别(男,女)[单选] mysql create table votes( name varchar(20), gender enum(男,女), hobby set(登山,游泳,篮球,武术) ); Query OK, 0 rows affected (0.21 sec)

mysql desc votes;

| Field | Type | Null | Key | Default | Extra |

| name | varchar(20) | YES | | NULL | | | gender | enum(男,女) | YES | | NULL | |

| hobby | set(登山,游泳,篮球,武术) | YES | | NULL | |

3 rows in set (0.02 sec)插入数据 mysql insert into votes values(张三,男,登山); Query OK, 1 row affected (0.05 sec)mysql insert into votes values(李四,1,登山,篮球); Query OK, 1 row affected (0.02 sec)mysql insert into votes values(王五,2,7); Query OK, 1 row affected (0.02 sec)mysql insert into votes values(赵六,2,15);

Query OK, 1 row affected (0.04 sec)mysql select * from votes;

| name | gender | hobby |

| 张三 | 男 | 登山 | | 李四 | 男 | 登山,篮球 | | 王五 | 女 | 登山,游泳,篮球 |

| 赵六 | 女 | 登山,游泳,篮球,武术 |

4 rows in set (0.00 sec)如表中数据想要查找所有喜欢登山的人

mysql select * from votes;

| name | gender | hobby |

| 张三 | 男 | 登山 | | 李四 | 男 | 登山,篮球 | | 王五 | 女 | 登山,游泳,篮球 |

| 赵六 | 女 | 登山,游泳,篮球,武术 |

4 rows in set (0.00 sec)mysql select * from votes where hobby 登山;

| name | gender | hobby |

| 张三 | 男 | 登山 |

1 row in set (0.00 sec) 并不能查出所有爱好登山的人。 要使用find_in_set函数 find_in_set(sub,str_list)如果sub在str_list中则返回下标如果不在返回0 str_list用逗号分割的字符串。

mysql select find_in_set(a,a,b,c);

find_in_set(a,a,b,c)
1

1 row in set (0.00 sec)mysql select find_in_set(d,a,b,c);

find_in_set(d,a,b,c)
0

1 row in set (0.00 sec)因此查询爱好登山的人

mysql select * from votes where find_in_set(登山,hobby);

| name | gender | hobby |

| 张三 | 男 | 登山 | | 李四 | 男 | 登山,篮球 | | 王五 | 女 | 登山,游泳,篮球 |

| 赵六 | 女 | 登山,游泳,篮球,武术 |

4 rows in set (0.00 sec)查询同时爱好登山和游泳的人

mysql select * from votes where find_in_set(登山,hobby) and find_in_set(游泳,hobby);

| name | gender | hobby |

| 王五 | 女 | 登山,游泳,篮球 |

| 赵六 | 女 | 登山,游泳,篮球,武术 |

2 rows in set (0.00 sec)本篇完