I want to store phone numbers as integers and I've created this SQL:
DROP TABLE `user_id_phone`;
CREATE TABLE `user_id_phone`
(
`user_id` int unsigned NOT NULL,
`country_code` smallint unsigned NOT NULL,
`number` bigint unsigned NOT NULL,
`ext` smallint unsigned NULL,
PRIMARY KEY (`country_code`, `number`, `ext`)
) ENGINE = InnoDB
But my server (10.4.14-MariaDB) creates field ext
as 'NOT NULL':
`ext` smallint(5) unsigned NOT NULL,
if ext
is a part of the composite primary key:
PRIMARY KEY (`country_code`, `number`, `ext`)
In case of ext
is not a part of the primary key:
PRIMARY KEY (`country_code`, `number`),
the field DDL is right after creation:
`ext` smallint(5) unsigned DEFAULT NULL,
Why?