[SQL] Single SQL to find if any record exists across several tables

Поиск
Список
Период
Сортировка
От Ertan Küçükoğlu
Тема [SQL] Single SQL to find if any record exists across several tables
Дата
Msg-id 002301d332d7$745b1500$5d113f00$@1nar.com.tr
обсуждение исходный текст
Ответы Re: [SQL] Single SQL to find if any record exists across several tables  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: [SQL] Single SQL to find if any record exists across several tables  (Feike Steenbergen <feikesteenbergen@gmail.com>)
Список pgsql-sql
Hello,

Using PostgreSQL 9.6.5 64bit running on Windows 10 64bit.

There are no foreign key across tables in database. There is a table where
company codes are kept. Most other tables includes company code value in a
column. Column name is same for all tables which is "fk".

Before deleting any company code row, I would like to be sure that it is not
used in anywhere. Currently I am running a separate query for each table but
that takes a lot of time and possibility to miss a table or two.

Is it possible to build a single SQL statement and include all tables in it
so that I receive single "count(fk)" sum across all tables?

Several sample SQLs run at the moment are as follows:
Select count(fk) from cari
Select count(fk) from sipbaslik
Select count(fk) from stkdepo
Select count(fk) from stkkart
Select count(fk) from stkhar

Thanks & regards,
Ertan Küçükoğlu




--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

В списке pgsql-sql по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: [SQL] SETOF any table records AS return in pgSQL functions
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: [SQL] Single SQL to find if any record exists across several tables