Home >Database >Mysql Tutorial >How to use integers in MySQL

How to use integers in MySQL

WBOY
WBOYforward
2023-05-30 11:08:231128browse

 Integer type of MySQL data type

When making data types, the range of selection should be as small as possible to meet the needs. The smaller the scope, the less resources it takes up.

  mysql> create table stu(
  -> stuid  tinyint
  -> );
  Query OK, 0 rows affected (0.00 sec)

  Unsigned integer type unsigned There is no negative number in the unsigned integer type, and the unsigned integer is twice the integer.

  mysql> create table stu1(
  -> stuid  tinyint unsigned
  -> );

Integers support display width. The display width is the minimum number of display digits. For example, int(11) means that the integer is represented by at least 11 digits. If there are not enough digits, fill it with 0. Display width does not work by default and must be combined with zerofill to work. The display size of the integer does not depend on the display width, but uses 0 for leading padding when the value is not enough for the specified number of digits

  mysql> create table stu2(
  -> sutid int(5) zerofill
  -> );

The above is the detailed content of How to use integers in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete