Home  >  Article  >  Database  >  About the data type display width n in MySQL

About the data type display width n in MySQL

黄舟
黄舟Original
2017-03-01 14:02:351471browse

When we create a table in MYSQL, we may often use int(10). Then what does this 10 mean exactly? What is the difference between it and 10 in varchar(10)?

For integer data, mysql supports specifying the display width in parentheses after the type name. Display width is generally used with zerofill. Zerofill, as the name suggests, is filled with 0s. When the number of digits is not enough to display, use 0 padding.

If zerofill is not used together, setting the display width in mysql will have no effect

Create a table

CREATE TABLE `t1` (
  `id1` int(3) unsigned zerofill NOT NULL DEFAULT '000',
  `id2` int(3) unsigned zerofill NOT NULL DEFAULT '000'
) ENGINE=InnoDB DEFAULT CHARSET=utf8


Insert data test


INSERT INTO `t1`(`id1`,`id2`) VALUES(123456,12);



Note: If a value larger than the width limit is inserted after setting the width, truncation or truncation will not be sent. It's an insertion error. When the width of the inserted value is greater than the set bandwidth, the width format actually has no meaning.

The above is about the display width n of the data type in MySQL. For more related content, please pay attention to the PHP Chinese website (www .php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn