存储国家/地区的最佳方式是在国家/地区表中。包括 ISO 3166 国家代码。将 ISO 代码存储为外键引用,大多数时候您不需要加入。
create table countries (
iso_country_code char(3) primary key,
country_name varchar(50) not null unique
);
insert into countries (country_name, iso_country_code) values
('AALAND ISLANDS', 'ALA'),
('AFGHANISTAN', 'AFG'),
('ALBANIA', 'ALB'),
...
('YEMEN', 'YEM'),
('ZAMBIA', 'ZMB'),
('ZIMBABWE', 'ZWE');
create table some_other_table_that_references_countries (
some_key ... primary key,
iso_country_code char(3) not null references countries (iso_country_code),
...
);
大多数情况下,您可能不需要加入,因为人们可以记住国家代码。