Learn Mysql:mysql with Mr. Wang integer type of data type

Source: Internet
Author: User

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/M02/83/A5/wKiom1d5vIHQGLqEAABb6J5Eogk661.png "alt = "Wkiom1d5vihqglqeaabb6j5eogk661.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

1

2

3

4

5

create tablestudent(

   id intprimary keyauto_increment,

   namevarchar(10),

   age tinyint

) charset utf8;

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A4/wKioL1d5vIHBWCO-AAAL3a3QVJ4377.png "alt = "Wkiol1d5vihbwco-aaal3a3qvj4377.png"/>
(iii) Insert data 1 insert a normal value

1

insertintostudent(name,age)values(‘zhangsan‘,25);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A5/wKiom1d5vIHQIzGDAAAZ9GbRMAE343.png "alt = "Wkiom1d5vihqizgdaaaz9gbrmae343.png"/>

2 inserting a value greater than the range

1

insertintostudent(name,age)values(‘lisi‘,200);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/83/A4/wKioL1d5vIGRezmcAAAJ_QGflHY504.png "alt = "Wkiol1d5vigrezmcaaaj_qgflhy504.png"/>

3 Inserting boundary values

1

insertintostudent(name,age)values(‘lisi‘,-128);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/A4/wKioL1d5vIGhfkZcAAAI0YMfAoY733.png "alt = "Wkiol1d5vighfkzcaaai0ymfaoy733.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

altertable student addage2 tinyint unsigned;

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/83/A5/wKiom1d5vIGhmOgpAAAm0EcIz3k678.png "alt = "Wkiom1d5vighmogpaaam0eciz3k678.png"/>

Add to Age2-1

1

insertintostudent(name,age,age2)values(‘lisi‘,24,-1);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A4/wKioL1d5vIKzoelSAAAJubGVJrA956.png "alt = "Wkiol1d5vikzoelsaaajubgvjra956.png"/>

Add 0

1

insert into student(name,age,age2)values(‘lisi‘,24,0);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/A5/wKiom1d5vIKBT04CAAAIwZR_pTw384.png "alt = "Wkiom1d5vikbt04caaaiwzr_ptw384.png"/>

So unsigned is greater than or equal to 0

2. Display width

It's just the width of the display and it doesn't have anything to do with the storage range.

1

altertable student addage3 tinyint(1);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/83/A4/wKioL1d5vILhXLdRAAAook4nelM892.png "alt = "Wkiol1d5vilhxldraaaook4nelm892.png"/>

Insert Age3=100

1

insertintostudent(name,age3)values(‘lisi‘,100);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A5/wKiom1d5vILS8b7EAAAIXncnhog125.png "alt = "Wkiom1d5vils8b7eaaaixncnhog125.png"/>

3 Zerofill

0 padding 00001 00005

If a column is Zerofill, the default is unsigned

Add a column

1

alter table student add age4 tinyint(5) zerofill;

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/A4/wKioL1d5vILCuvx_AAA4vxnuBJ8685.png "alt = "Wkiol1d5vilcuvx_aaa4vxnubj8685.png"/>

Inserting Data age4=9

1

insertintostudent(name,age4)values(‘lisi‘,9);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/83/A5/wKiom1d5vIPhNwnzAAAj-hdzq5s943.png "alt = "Wkiom1d5viphnwnzaaaj-hdzq5s943.png"/>

Iv. Instructional Videos

Http://edu.51cto.com/course/course_id-6420.html




This article is from "Learn programming with Mr. Wang" blog, please be sure to keep this source http://teacherwang.blog.51cto.com/10946447/1795473

Learn Mysql:mysql with Mr. Wang integer type of data type

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.