470,614 Members | 1,425 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

one to one and many to many => one to (one and many)

I have these tables. There are many languages, and many countries.
Every country has many (some subset of) languages.

create table countries (
country_id serial primary key,
country_name varchar(128) unique not null

create table languages (
language_id serial primary key,
language_name varchar(128) unique not null

create table countries_languages (
country_id int references countries,
language_id int references languages,
primary boolean not null default false,
unique(country_id, language_id)


Politics clouding reality as it always does, each country must be
assigned a primary language. That's the primary column in
countries_languages. This column doesn't exist yet, but is the best
way I can think of to solve the problem.

For each country there should be no more than one row in
countries_languages for which primary is true.

How do I enforce it in the database? Is there a clean and portable way
to do it? Or at least a clean postgresql-only way to do it?

I don't want to make a separate one-to-(zero or one) table, because
all the important stuff will still work with multiple languages per
country. If there is a separate countries_primarylanguage table, it
must be guaranteed consistent with countries_language.
Jul 19 '05 #1
0 1296

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Christian Schmidbauer | last post: by
34 posts views Thread by Mark Moore | last post: by
8 posts views Thread by someone | last post: by
8 posts views Thread by Shawn Minisall | last post: by
6 posts views Thread by bill | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.