On May 9, 2004, at 6:54 AM, eno wrote:


Puneet Kishor wrote:

this is likely a common and easy answer, so my <blushes> for not being able to figure it out.
How do I test for the existence of a table or a view so I can do something like...
if <table|view> exists
then DROP <table|view>
else CREATE <table|view> ()...

what I do in such situations is


SELECT 1 FROM sqlite_master WHERE type='table' AND name ='whatever';

which selects a single "1" row or nothing. A more portable way (between different SQL implementations) might be

SELECT 1 FROM tablename WHERE 1 == 0

If this fails the tablename table doesn't exist, otherwise it exists.

The problem of generating a potentially existing table can obviously be tackled by exec'ing the CREATE TABLE statement, and catching the "table already exists" error in case it occurs.


Thanks... this technique assumes I am working with SQLite externally with some scripting language. That way, yes, your suggestion would be great. I was hoping for some method from within SQLite that could be used in a SQL statement...



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to