Complete DECIMAL type reference: DECIMAL(M,D) syntax, precision limits (M≤65, D≤38), SIGNED/UNSIGNED/ZEROFILL options, and rounding behavior.
DECIMAL[(M[,D])] [SIGNED | UNSIGNED | ZEROFILL]CREATE TABLE t1 (d DECIMAL UNSIGNED ZEROFILL);
INSERT INTO t1 VALUES (1),(2),(3),(4.0),(5.2),(5.7);
Query OK, 6 rows affected, 2 warnings (0.16 sec)
Records: 6 Duplicates: 0 Warnings: 2
Note (sql 1265): Data truncated for column 'd' at row 5
Note (sql 1265): Data truncated for column 'd' at row 6
SELECT * FROM t1;
+------------+
| d |
+------------+
| 0000000001 |
| 0000000002 |
| 0000000003 |
| 0000000004 |
| 0000000005 |
| 0000000006 |
+------------+INSERT INTO t1 VALUES (-7);
ERROR 1264 (22003): Out of range value for column 'd' at row 1CREATE TABLE decimal_signed_example (
description VARCHAR(20),
sz10_0 DECIMAL,
sz6_2 DECIMAL(6,2),
sz20_19 DECIMAL(20,19) SIGNED
);SET @pi = 3.1415926535897932384626433832795;INSERT INTO decimal_signed_example VALUES
('Pi', @pi, @pi, @pi),
('Series', 1234.567890123, 1234.567890123, 1.234567890123),
('Negative', -1234.567890123, -1234.567890123, -1.234567890123),
('Various', 1234567890, 9999.99, 9.9999999999999999999);SELECT * FROM decimal_signed_example;
+-------------+------------+----------+------------------------+
| description | sz10_0 | sz6_2 | sz20_19 |
+-------------+------------+----------+------------------------+
| Pi | 3 | 3.14 | 3.1415926535897932385 |
| Series | 1235 | 1234.57 | 1.2345678901230000000 |
| Negative | -1235 | -1234.57 | -1.2345678901230000000 |
| Various | 1234567890 | 9999.99 | 9.9999999999999999999 |
+-------------+------------+----------+------------------------+CREATE TABLE decimal_unsigned_example (
description VARCHAR(20),
sz10_0 DECIMAL UNSIGNED,
sz6_2 DECIMAL(6,2) UNSIGNED,
sz20_19 DECIMAL(20,19) UNSIGNED
);SET @pi = 3.1415926535897932384626433832795;INSERT INTO decimal_unsigned_example VALUES
('Pi', @pi, @pi, @pi),
('Series', 1234.567890123, 1234.567890123, 1.234567890123),
('Various', 1234567890, 9999.99, 9.9999999999999999999);SELECT * FROM decimal_unsigned_example;
+-------------+------------+---------+-----------------------+
| description | sz10_0 | sz6_2 | sz20_19 |
+-------------+------------+---------+-----------------------+
| Pi | 3 | 3.14 | 3.1415926535897932385 |
| Series | 1235 | 1234.57 | 1.2345678901230000000 |
| Various | 1234567890 | 9999.99 | 9.9999999999999999999 |
+-------------+------------+---------+-----------------------+TRUNCATE decimal_signed_example;
-- Disable strict mode
SET sql_mode=(SELECT REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''));
INSERT INTO decimal_signed_example VALUES
('OK', 9999999999.4, NULL, NULL),
('Rounded overflow', 9999999999.5, NULL, NULL),
('Overflow', 10000000000, NULL, NULL),
('OK', -9999999999.4, NULL, NULL),
('Rounded underflow', -9999999999.5, NULL, NULL),
('Underflow', -10000000000, NULL, NULL),
('OK', NULL, 9999.994, NULL),
('Rounded overflow', NULL, 9999.995, NULL),
('Overflow', NULL, 10000, NULL),
('OK', NULL, -9999.994, NULL),
('Rounded underflow', NULL, -9999.995, NULL),
('Underflow', NULL, -10000, NULL),
('OK', NULL, NULL, 9.99999999999999999994),
('Rounded overflow', NULL, NULL, 9.99999999999999999995),
('Overflow', NULL, NULL, 10),
('OK', NULL, NULL, -9.99999999999999999994),
('Rounded underflow', NULL, NULL, -9.99999999999999999995),
('Underflow', NULL, NULL, -10);Note (sql 1265): Data truncated for column 'sz10_0' at row 1
Warning (sql 1264): Out of range value for column 'sz10_0' at row 2
Warning (sql 1264): Out of range value for column 'sz10_0' at row 3
Note (sql 1265): Data truncated for column 'sz10_0' at row 4
Warning (sql 1264): Out of range value for column 'sz10_0' at row 5
Warning (sql 1264): Out of range value for column 'sz10_0' at row 6
Note (sql 1265): Data truncated for column 'sz6_2' at row 7
Warning (sql 1264): Out of range value for column 'sz6_2' at row 8
Warning (sql 1264): Out of range value for column 'sz6_2' at row 9
Note (sql 1265): Data truncated for column 'sz6_2' at row 10
Warning (sql 1264): Out of range value for column 'sz6_2' at row 11
Warning (sql 1264): Out of range value for column 'sz6_2' at row 12
Note (sql 1265): Data truncated for column 'sz20_19' at row 13
Warning (sql 1264): Out of range value for column 'sz20_19' at row 14
Warning (sql 1264): Out of range value for column 'sz20_19' at row 15
Note (sql 1265): Data truncated for column 'sz20_19' at row 16
Warning (sql 1264): Out of range value for column 'sz20_19' at row 17
Warning (sql 1264): Out of range value for column 'sz20_19' at row 18SELECT * FROM decimal_signed_example;+-------------------+-------------+----------+------------------------+
| description | sz10_0 | sz6_2 | sz20_19 |
+-------------------+-------------+----------+------------------------+
| OK | 9999999999 | NULL | NULL |
| Rounded overflow | 9999999999 | NULL | NULL |
| Overflow | 9999999999 | NULL | NULL |
| OK | -9999999999 | NULL | NULL |
| Rounded underflow | -9999999999 | NULL | NULL |
| Underflow | -9999999999 | NULL | NULL |
| OK | NULL | 9999.99 | NULL |
| Rounded overflow | NULL | 9999.99 | NULL |
| Overflow | NULL | 9999.99 | NULL |
| OK | NULL | -9999.99 | NULL |
| Rounded underflow | NULL | -9999.99 | NULL |
| Underflow | NULL | -9999.99 | NULL |
| OK | NULL | NULL | 9.9999999999999999999 |
| Rounded overflow | NULL | NULL | 9.9999999999999999999 |
| Overflow | NULL | NULL | 9.9999999999999999999 |
| OK | NULL | NULL | -9.9999999999999999999 |
| Rounded underflow | NULL | NULL | -9.9999999999999999999 |
| Underflow | NULL | NULL | -9.9999999999999999999 |
+-------------------+-------------+----------+------------------------+CREATE TABLE decimal_zerofill_example (
description VARCHAR(20),
sz10_0 DECIMAL ZEROFILL,
sz6_2 DECIMAL(6,2) ZEROFILL,
sz20_19 DECIMAL(20,19) ZEROFILL
);SET @pi = 3.1415926535897932384626433832795;INSERT INTO decimal_zerofill_example VALUES
('Pi', @pi, @pi, @pi),
('Series', 1234.567890123, 1234.567890123, 1.234567890123),
('Various', 1234567890, 9999.99, 9.9999999999999999999);SELECT * FROM decimal_zerofill_example;
+-------------+------------+---------+-----------------------+
| description | sz10_0 | sz6_2 | sz20_19 |
+-------------+------------+---------+-----------------------+
| Pi | 0000000003 | 0003.14 | 3.1415926535897932385 |
| Series | 0000001235 | 1234.57 | 1.2345678901230000000 |
| Various | 1234567890 | 9999.99 | 9.9999999999999999999 |
+-------------+------------+---------+-----------------------+