View video tutorial

MYSQL SMALLINT

MYSQL

The MySQL SMALLINT data type is used to store small numeric values ​​of 16 bits.

MySQL SMALLINT


➔ The SMALLINT data type can hold 2-byte integer numeric values.

➔ The SMALLINT data type is signed by default, which means it can store both positive and negative values.

➔ Adding the UNSIGNED keyword after SMALLINT turns off negative values ​​and increases the maximum positive value.

➔ If ZEROFILL is specified after SMALLINT, MySQL automatically adds the UNSIGNED attribute.

➔ The size parameter pads the displayed value with leading zeros up to the specified display width.

SMALLINT Range:
Type Signed Range Unsigned Range Storage
SMALLINT -32768 to 32767. This is default. 0 to 65535 2 byte

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

Create table:

Example

/*  Table names and column names can be changed. */
CREATE TABLE IF NOT EXISTS mytable (
   col1 SMALLINT,
   col2 SMALLINT UNSIGNED
);

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 */
INSERT INTO mytable VALUES (32767, 65535);

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.