Skip to content
Brian edited this page May 15, 2016 · 3 revisions
 dropTable(tableName[, options])

JSQL query used to delete a table from the database.

Table of Contents

Parameters

tableName

The name of the table to drop. dropTable will throw an error if tableName is an empty string or ends with a period.

If the name contains a space, everything after the last space will be ignored.

If the name contains a period, everything before the last period (which is also before the last space) will be used to choose the schema to find the table in. If the name does not contain a period, the default schema will be used.

The name "triggers" is reserved, and may not be used for the table.

options (optional)

See options for additional information.

Options for modifying the behavior of the dropTable query.

Property Default Explanation
dropTableIfExists true If the named table doesn't exist and this option is false, the query will throw an error.
ifExists Alias for dropTableIfExists
useTransaction null If set to a Transaction object, executing the query will add the query to the transaction's queue instead of actually executing it.

Returns

The dropTable function returns a DropTable object, which is a subclass of cls.QueryBuilder. However, there is nothing to the building of a dropTable query beyond the table name, so only one function is available:

execute([options])

Performs the table deletion operation.

options.dropTableIfExists (alias ifExists) and options.useTransaction can override the same options specified in dropTable and cls.DefaultOptions.

This function will return true if the table is dropped successfully. If options.dropTableIfExists is true and the table doesn't exist, this function will return false and take no action. If options.dropTableIfExists is false and the table doesn't exist, this function will throw an error.

Clone this wiki locally