On Wed, Jul 1, 2009 at 5:29 PM, Rick Ratchford<[email protected]> wrote:
> 1. Determine if the table has already been created due to a prior run.
>
> 2. If so, to remove the information currently in that table and replace it
> with new information.
>
> I'm not sure how to determine whether the table already exists.
>
> If it does exist, I suppose I can then use the SQL Delete to delete all the
> records and then write the new stuff. If this is not the way to do it, maybe
> someone can suggest the proper way.

Well, here are a few commands that may give you some ideas, and you
can see what works best for you....

Here is how you can use sqlite_master to determine if a table exists:

    SELECT count(*) FROM sqlite_master WHERE tbl_name = 'Foo';
    -- returns 1 if table exists, 0 otherwise

If you want to drop your table and then create it, you could do this:

    DROP TABLE Foo;
    -- It's okay to execute this command, even if Foo does not exist already.

    CREATE TABLE Foo ( ... );

Here you can see whether or not a table contains any rows at all:

    SELECT count(*) FROM Foo;
    -- returns 0 if table is empty

If you want to clean out your table:

    DELETE FROM Foo;
    -- This will delete all rows from Foo

If you just want to update some already existing data:

    UPDATE Foo SET column2 = 33 WHERE column1 = 1;
    -- This lets you update (modify) information that already exists
in the table


-David
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to