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

From: Shakespeare <>
Date: Sat, 17 Oct 2009 10:50:16 +0200
Message-ID: <4ad9854f$0$83233$>

Ramon F Herrera schreef:
> On Oct 16, 7:48 pm, Shakespeare <> wrote:
>> Ramon F Herrera schreef:
>>> All my database accesses are done through Pro*C/C++.
>>> Sometimes my code needs to verify whether a table exists. Years ago, I
>>> was about to post that particular  questions here. I then realized
>>> that the following statements achieve the desired results:
>>> EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE
>>> table_name = :table_name;
>>> if (howMany == 1)
>>>     doThis();
>>> else
>>>    doThat();
>>> Is that "the" proper way?
>>> -Ramon
>> I always get a bit worried if an application has to check whether a
>> table exists.... should they not be there just by design?
>> Shakespeare

> Good point. The thing about my design is that I have "a table of
> tables". The code in question is for my internal use, and I type it
> from the Unix prompt. Let's say I have a bunch of company clients and
> the command in question tells me when was the last time such company
> made a payment or something.
> For policy and other reasons I treat every company as a separate
> entity with their own tables. Some companies demand not to share table
> space with other companies.
> Therefore the interaction would look like this:
> % last_payment google
> The program -after checking that a table named "google" does not
> exist- will retort:
> "Are you kidding me, Ramon? `google' is not your client"
> -RFH

Ok, fair enough. This seems a legitimate way of checking, as long as your own scripts are involved. You convinced me!!

Shakespeare Received on Sat Oct 17 2009 - 03:50:16 CDT

Original text of this message