docs.roxen.comBack to normal mode
DocsRoxen2.1TutorialsDatabase Tutorial
Copyright  2001, Roxen Internet Software
Suggestions, comments & compliments
manuals@roxen.com

Dropping

To delete indices, tables or databases, the DROP command is used in its variations:

To delete an index (where the CREATE INDEX syntax is used), the syntax is:

DROP INDEX name

To drop a table the syntax is:

DROP TABLE name

The table, its contents and definition will be deleted from the database irrevocably.

To drop a database altogether (where supported), you can use

DROP DATABASE name

The pike SQL-interface provides a specific-purpose function to drop a database: this is mainly for compatibility with MiniSQL where the operation of dropping a database is demanded to a specific-purpose API function, named drop_db.

Using SQL:

object db = Sql.sql("mysql://admin:pass@localhost");
mixed exception;
exception = catch {
  db->query("DROP DATABASE test");
};
if(exception)
{
  werror("Error while dropping the database: "+db->error()+"\n");
  throw(exception);
}

Using the API functions:

object db=Sql.sql("msql://admin:pass@localhost");
mixed exception;
exception=catch {
  db->drop_db("test");
};
if(exception)
{
  werror("Error while dropping the database: "+db->error()+"\n");
  throw(exception);
}

Notice that I haven't either tried to fetch results (there's no result to fetch anyways) and the exception handling has been very limited, and for diagnostic purposes only: these operations are really meant to be used only interactively.