Re: Is this the sanctioned way to ascertain a table's existence?

From: Serge Rielau <srielau_at_ca.ibm.com>
Date: Sat, 17 Oct 2009 13:24:10 +0200
Message-ID: <7jtnqrF37lqjqU1_at_mid.individual.net>



Out of principle I would never use COUNT() to check for existence. Imagine a bowl of rice. does it require counting the rice grains inside the bowl to know whether it is empty or not? One glance should be enough.
In SQL Terms that would be an EXISTS predicate. Or if you want to keep it simple in your case

SELECT 1 FROM USER.TABLES WHERE table_name = :table_name AND ROWNUM < 2

In teh case of USER_TABLE by design you may only get one row, but if you use COUNT() here chances are someone will copy your code and use it somewhere else where there are a million buggers to count.

Cheers
Serge

-- 
Serge Rielau
SQL Architect DB2 for LUW
IBM Toronto Lab
Received on Sat Oct 17 2009 - 06:24:10 CDT

Original text of this message