Junior — Middle
What is the main function of the TINYINT data type in a database?
sobes.tech AI
Answer from AI
The TINYINT data type in a database is used to store very small integer numbers. It typically occupies 1 byte of memory and can store values in the range from 0 to 255 (if unsigned) or from -128 to 127 (if signed).
The main purpose of TINYINT is to save space when storing numerical data where the values do not exceed these limits. For example, it is convenient for storing flags, statuses, small counters, or categories.
Example of usage in SQL:
CREATE TABLE users (
id INT PRIMARY KEY,
is_active TINYINT UNSIGNED NOT NULL DEFAULT 1
);
Here, the is_active field can store 0 or 1, saving space compared to using a larger type.