Assigning the correct data type to a column so MariaDB stores values efficiently, accurately, and with optimal performance.
Data types tell MariaDB how much space to reserve, which operations are allowed, and how to validate inserted values. Choosing correctly prevents over-allocating storage and avoids runtime casting errors.
Use INT
for up to ~2.1 billion signed values; switch to BIGINT
for larger ranges.Add UNSIGNED
when negative numbers are impossible, doubling the positive range without extra space.
Prefer DECIMAL(p,s)
for fixed-precision currency (e.g., DECIMAL(10,2)
for prices up to 99 999 999.99). Avoid FLOAT
/DOUBLE
because binary fractions can cause rounding errors.
Choose VARCHAR(n)
for variable-length strings ≤65 535 bytes; MariaDB stores only actual length, saving space.Use TEXT
for longer blobs of text that rarely participate in indexed searches.
Use DATE
for calendar dates, DATETIME
for combined date & time, and TIMESTAMP
when you need automatic UTC conversion or default current time.
Yes. Run ALTER TABLE table_name MODIFY column_name NEW_TYPE [...options];
in a maintenance window.Always back up first, and ensure the new type is compatible to avoid data truncation.
• Use BIGINT UNSIGNED
for Order IDs if you expect millions of rows.
• Store product prices as DECIMAL(10,2)
.
• Track stock in INT UNSIGNED
.
• Record order dates with DATETIME
.
Query INFORMATION_SCHEMA.COLUMNS
to review types and sizes, then run representative inserts & aggregations to benchmark performance.
.
Yes, but expect table locking. Schedule downtime or use online DDL in MariaDB Enterprise.
No. MariaDB stores only the actual length plus 1–2 bytes for length metadata.
Use ENUM for short, fixed lists such as order status ('pending','shipped','delivered'). It stores values compactly as integers but remains human-readable.