Постановка задачи

Задача - ведение базы данным по известным ( в космическом масштабе ) персонам, а именно слудующих их атрибутов:

  1. Descr  -> имя и т.п.
  2. Feature   -> преобладающая черта характера
  3. Occupation  -> род деятльности
  4. Country  -> где проживает
  5. Sexual_potention  -> процент сексуальности
  6. Photo  -> фотография
  7. dateofbirth -> дата рождения
  8. If_happy  -> счастлив ли по жизни

Для этого создается таблица “persons” ( в формате команд PostgreSQL ):

create sequence person_id_seq; -- эмулятор поля-счетчика

create table persons (
 id integer default nextval('person_id_seq'),
 feature_id integer,
 occupation_id integer,
 country_id integer,
 descr text not null,
 sexual_potention float,
 photo bytea,
 if_happy boolean,
 dateofbirth date
);

Пункты 2)..4) должны содержать выбираемые значения, поэтому на них ведутся справочные таблицы:

Черты характера :

create sequence feature_id_seq;

create table features (
 id integer default nextval('feature_id_seq'),
 descr text not null
);

Рода деятельности :

create sequence occupation_id_seq;

create table occupations (
 id integer default nextval('occupation_id_seq'),
 descr text not null
);

Страны :

create table countries (

id integer default nextval('country_id_seq'),
 continent_id integer,
 descr text not null
);

Так как стран во вселенной может быть очень много, то придется их классифицировать на

континенты :

create sequence continent_id_seq;

create table continents (
 id integer default nextval('continent_id_seq'),
 planet_id integer,
 descr text not null
);

а континенты, в свою очередь - на планеты :

create sequence planet_id_seq;

create table planets (
 id integer default nextval('planet_id_seq'),
 descr text not null
);

Автоматизированная подготовка БД к работе - смотрите главу Создание БД.