For now, I just delete the db file if it exists already. So that I don’t need to call DROP TABLE IF EXISTS mytab. I guess directly deleting the db file can be faster than the latter. Is it so?
On Tue, Sep 3, 2019 at 3:06 PM Simon Slavin <slav...@bigfraud.org> wrote: > On 3 Sep 2019, at 8:57pm, Peng Yu <pengyu...@gmail.com> wrote: > > > If I try to create a table that already exists, sqlite will give me an > error. Is there way to issue one command to create a table, but if there is > already a table with the same name, drop it then create the new table? > Thanks. > > Assuming that the new table has a different structure to the old one, do > it in two commands: > > DROP TABLE IF EXISTS MyTable; > CREATE TABLE MyTable ...; > > Neither of those commands will generate an error. > > If you are sure that the new table has the same structure as the old one, > you can do > > CREATE TABLE IF NOT EXISTS MyTable ...; > DELETE FROM MyTable; > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > -- Regards, Peng _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users