View video tutorial

MYSQL TINYINT

MYSQL

The MySQL TINYINT data type is used to store very small numeric values.

MySQL TINYINT


➔ The TINYINT data type can hold 1-byte integer numeric values.

➔ Adding the UNSIGNED keyword after TINYINT turns off negative values ​​and increases the maximum positive value, thereby shifting the range to 0-255.

➔ If ZEROFILL is specified after TINYINT, MySQL automatically adds the UNSIGNED attribute and the output is padded with leading zeros up to the display width.

TINYINT Range:
Type Signed Range Unsigned Range Storage
TINYINT -128 to 127. This is default. 0 to 256 1 byte

Syntax
TINYINT(size) [SIGNED | UNSIGNED | ZEROFILL]

Create table:

Example

CREATE TABLE IF NOT EXISTS mytable (
   col1 TINYINT,
   col2 TINYINT UNSIGNED,
   col3 TINYINT ZEROFILL
);

Copy the code and try it out practically in your learning environment.


Insert value:(valid)

Example

/* SIGNED range: -128 to 127 */
/* UNSIGNED range: 0 to 255 */
/* ZEROFILL range: 0 to 255 */
INSERT INTO mytable VALUES (127, 255, 255)

Copy the code and try it out in your learning environment.


Query value:

Example

/* Query all data */
SELECT * FROM mytable;

Copy the code and try it out practically in your learning environment.