List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:October 6 1999 4:43pm
Subject:Re: TABLE EXISTS
View as plain text  
At 8:16 AM -0500 10/6/99, Carsten H. Pedersen wrote:
>sinisa@stripped wrote:
>>
>> toxalot@stripped writes:
>>  > I see in the handbook that there is a way to see that a table exists
>>before
>>  > dropping it, but how do you check if one exists before trying to
>>create it?
>>  >
>>  > Jennifer
>>
>> Hi!
>>
>> IF EXISTS works with DROP and CREATE, with a later being rather
>> recent.
>>
>> Sinisa
>
>Alternatively, you can do "select 1 from <tablename>". You either
>get a result set of one record containing a 1 or an error indicating
>the table doesn't exist.


No, you get a result set consisting of "1" for *each row* of the table
name.  These queries are faster:

SELECT COUNT(*) FROM tbl_name
SELECT * FROM tbl_name WHERE 1 = 0


Also, for CREATE TABLE, the clause is IF NOT EXISTS, not IF EXISTS.

--
Paul DuBois, paul@stripped
Thread
TABLE EXISTStoxalot6 Oct
  • Re: TABLE EXISTSsinisa6 Oct
  • Re: TABLE EXISTSCarsten H. Pedersen6 Oct
    • Re: TABLE EXISTSPaul DuBois6 Oct
      • Re: TABLE EXISTStoxalot7 Oct