Learn Mysql:mysql with Mr. Wang integer type of data type
Teacher: Wang Shaohua QQ Group No.: 483773664
MySQL data types include integer type, floating-point type, fixed-point number type, date and time type, string type, and binary data type.
Learning Goals
What types are included in an integral type and their range of values
Take tinyint as an example to explain the three attributes that define an integral type
First, Introduction
An integer type is the most basic data type in a database.
Both integer and smallint types are supported in standard SQL.
In addition to supporting these two types, the MySQL database extends support for tinyint, mediumint, and bigint.
Integer type is the most important to grasp its range of values
Ii. Range of values
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A2/wKioL1d5Ho-jMfUmAABb6J5Eogk954.png " >
Third, take tinyint as an example (a) The design principles of the column
Storage: Range of storage
No waste: Occupy space
(ii) Creation of a table
12345 |
create table student( id int primary key auto_increment, name varchar (10), age tinyint ) charset utf8; |
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A3/wKiom1d5HpbTCLfaAAAL3a3QVJ4557.png " >
(iii) Insert data 1 insert a normal value
1 |
insert into student( name ,age) values ( ‘zhangsan‘ ,25); |
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/A2/wKioL1d5HqbQDQG9AAAZ9GbRMAE870.png " >
2 inserting a value greater than the range
1 |
insert into student(name,age) values ( ‘lisi‘ ,200); |
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A3/wKiom1d5HqfwasLfAAAJ_QGflHY727.png " >
3 Inserting boundary values
1 |
insert into student( name ,age) values ( ‘lisi‘ ,-128); |
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/A2/wKioL1d5HqvjulT6AAAI0YMfAoY407.png " >
(d) Optional attributes of integer type
1 |
数据类型 (显示宽度) unsigned zerofill |
Display width: Only makes sense when filling at 0
Unsigned: Unsigned type (non-negative)
zerofill:0 Fill
1 unsigned
Add a column of unsigned type to student
1 |
alter table student add age2 tinyint unsigned; |
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/A3/wKiom1d5HrCQkpq1AAAm0EcIz3k909.png " >
Add to Age2-1
insert
into
student (
name
,age,age2)
values
(
' Lisi '
Learn Mysql:mysql with Mr. Wang integer type of data type