TINYINT

TINYINT is an 8-bit signed integer data type used to store integer values ranging from -128 to 127. It can efficiently save storage space as it only uses one byte to represent the value.

Syntax

TINYINT

Example

  1. Create a table with a TINYINT type column:
    CREATE TABLE example_table (
        id TINYINT
    );
2. Insert data into a column of type `TINYINT`:
INSERT INTO example_table (id) VALUES (-100);
INSERT INTO example_table (id) VALUES (100);
  1. Query data from a TINYINT type column:
    SELECT id FROM example_table;
  2. Using TINYINT type columns for conditional queries:
    SELECT id FROM example_table WHERE id > -50;
5. Create a table with a `TINYINT` type column (specify the maximum display width):
CREATE TABLE example_table2 (
    age TINYINT
);
6. Insert data into a `TINYINT` type column (specify maximum display width):
INSERT INTO example_table2 (age) VALUES (25y);
  1. TINYINT constant format:
 SELECT 11y

Notes

  • The TINYINT type is only suitable for storing smaller integer values. For larger values, it is recommended to use the INT or BIGINT type.
  • When using the TINYINT type to store negative numbers, the range is -128 to -1. Attempting to insert a negative number outside this range will result in an overflow error.
  • When using the TINYINT type to store positive numbers, the range is 1 to 127. Attempting to insert a positive number outside this range will result in an overflow error.