agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Ertan Küçükoðlu <ertan.kucukoglu@1nar.com.tr>
To: pgsql-sql@postgresql.org
Subject: Single SQL to find if any record exists across several tables
Date: Thu, 21 Sep 2017 15:45:02 +0300
Message-ID: <002301d332d7$745b1500$5d113f00$@1nar.com.tr> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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



view thread (3+ messages)  latest in thread

Message-ID: <002301d332d7$745b1500$5d113f00$@1nar.com.tr>
Permalink:  ../002301d332d7$745b1500$5d113f00$@1nar.com.tr/
Also on:    postgresql.org/message-id/002301d332d7$745b1500$5d113f00$@1nar.com.tr

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ertan.kucukoglu@1nar.com.tr
  Subject: Re: Single SQL to find if any record exists across several tables
  In-Reply-To: <002301d332d7$745b1500$5d113f00$@1nar.com.tr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox