Обсуждение: data integrity

Поиск
Список
Период
Сортировка

data integrity

От
Sandis
Дата:
Hello pgsql-sql,

sorry for my question that is obviously a kind of lame and not
related directly to postges, but i
never dealt with it before & need an idea what to do right now.

there is a db with a few tables that have related (joined) fields.
if record in a one table (auxiliary) gets deleted (along with it's primary key),
reference to it in another table (main) points to nowhere.
then doing a complex query with a join on that tables doesn't return
such corrupted rows that contains references to deleted rows in other
tables.

what's the solution? should i check if this 'project', for example,
have 'contacts' associated with it, and do not allow user to delete it,
than show that 'contacts' list and ask if she wants delete all of them?
or may be dont show a list, but just warn that there is $number
'contacts' related to this 'project', do you want to delete them all?

how about joins in delete query?
DELETE FROM projects, contacts WHERE projects.contact = contacts.id
AND projects.id = '$id';

he, i wrote the answer myself. may be dont send it at all?

can someone suggest some good online resource where such common sql topics
discussed?

thanks
--:)--
Best regards,Sandis                          mailto:sandisj@parks.lv




Re: data integrity

От
Jesus Aneiros
Дата:
On Tue, 15 Aug 2000, Sandis wrote:

> there is a db with a few tables that have related (joined) fields. if
> record in a one table (auxiliary) gets deleted (along with it's

I would say this is the primary table.

> primary key), reference to it in another table (main) points to

And this is the secondary tab,le which references the other.

> what's the solution? should i check if this 'project', for example,

The solution is called referential integrity. you should use the foreign
key and references clause with cascade.

> can someone suggest some good online resource where such common sql topics
> discussed?

I would like to know such a place.

Jesus.