Drop More than One Table at a Time

Jim_KnicelyJim_Knicely - Select Field - Administrator

The DROP TABLE command removes a table and its projections. You can drop more than one table at a time by specifying a comma delimited set of tables!

Example:

dbadmin=> CREATE TABLE test1 (c INT);
CREATE TABLE

dbadmin=> DROP TABLE test1;
DROP TABLE

That was easy. How about dropping more than one table?

dbadmin=> CREATE TABLE test2 (c1 INT, c2 VARCHAR);
CREATE TABLE

dbadmin=> CREATE TABLE test3 (c1 INT, c2 VARCHAR, c3 BOOLEAN);
CREATE TABLE

dbadmin=> CREATE TABLE test4 (c1 CHAR(1));
CREATE TABLE

At first you might be tempted to run a DROP TABLES command to drop multiple tables but that won’t work :)

dbadmin=> DROP TABLES test2, test3, test4;
ERROR 4856:  Syntax error at or near "TABLES" at character 6
LINE 1: DROP TABLES test2, test3, test4;
            ^

It’s still the same simple DROP TABLE command:

dbadmin=> DROP TABLE test2, test3, test4;
DROP TABLE

Helpful Link:
https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/Statements/DROPTABLE.htm

Have fun!

Sign In or Register to comment.