DROP statement

Description

Removes objects from the database.

Syntax

DROPDBSPACE dbspace-name
| { DATATYPE [ IF EXISTS ]
| DOMAIN [ IF EXISTS ] } datatype-name
| EVENT [ IF EXISTS ]  event-name
| INDEX [ IF EXISTS ]  [ [ owner].table-name.]index-name
| JOIN INDEXowner.]join-index-name
| MESSAGE message-number
| TABLE [ IF EXISTS ]  [ owner.]table-name
| VIEW [ IF EXISTS ]  [ owner.]view-name
| PROCEDURE [ IF EXISTS ]  [ owner.]procedure-name
| FUNCTION [ IF EXISTS ]  [ owner.]function-name }

Examples

Example 1

Drops the Departments table from the database:

DROP TABLE Departments

Example 2

Drops the emp_dept view from the database:

DROP VIEW emp_dept

Usage

DROP removes the definition of the indicated database structure. If the structure is a dbspace, then all tables with any data in that dbspace must be dropped or relocated prior to dropping the dbspace; other structures are automatically relocated. If the structure is a table, all data in the table is automatically deleted as part of the dropping process. Also, all indexes and keys for the table are dropped by DROP TABLE. However, you cannot drop the table if any join indexes use that table. You must first use DROP JOIN INDEX to remove the join indexes.

Use the IF EXISTS clause if you do not want an error returned when the DROP statement attempts to remove a database object that does not exist.

DROP INDEX deletes any explicitly created index. It deletes an implicitly created index only if there are no unique or foreign-key constraints or associated primary key.

DROP INDEX for a nonunique HG index fails if an associated unenforced foreign key exists.

WARNING!  Do not delete views owned by the DBO user. Deleting such views or changing them into tables might cause problems.

DROP TABLE, DROP INDEX, DROP JOIN INDEX, and DROP DBSPACE are prevented whenever the statement affects a table that is currently being used by another connection.

DROP TABLE is prevented if the primary table has foreign-key constraints associated with it, including unenforced foreign-key constraints

DROP TABLE is also prevented if the table has an IDENTITY column and IDENTITY_INSERT is set to that table. To drop the table you must clear IDENTITY_INSERT, that is, set it to ' ' (an empty string), or set it to another table name.

A foreign key can have either a nonunique single or a multicolumn HG index. A primary key may have unique single or multicolumn HG indexes. You cannot drop the HG index implicitly created for an existing foreign key, primary key, and unique constraint. If a DBA is dropping a join index belonging to another user, the join index name must be qualified with an owner name.

The four initial dbspaces are SYSTEM, IQ_SYSTEM_MAIN, IQ_SYSTEM_TEMP, and IQ_SYSTEM_MSG. You cannot drop these initial dbspaces, but you may drop dbspaces from the IQ main store or catalog store, which may contain multiple dbspaces, as long as at least one dbspace remains with readwrite mode.

You must drop tables in the dbspace before you can drop the dbspace. An error is returned if the dbspace still contains user data; other structures are automatically relocated when the dbspace is dropped. You can drop a dbspace only after you make it read-only.

NoteA dbspace may contain data at any point after it is used by a command, thereby preventing a DROP DBSPACE on it.

For more information on modifying dbspaces, see “Working with dbspaces” in Chapter 5, “Working with Database Objects” in the System Administration Guide: Volume 1.

DROP PROCEDURE is prevented when the procedure is in use by another connection.

DROP DATATYPE is prevented if the data type is used in a table. You must change data types on all columns defined on the user-defined data type to drop the data type. It is recommended that you use DROP DOMAIN rather than DROP DATATYPE, as DROP DOMAIN is the syntax used in the ANSI/ISO SQL3 draft.


Side effects

Automatic commit. Clears the Data window in dbisql. DROP TABLE and DROP INDEX close all cursors for the current connection.

Local temporary tables are an exception; no commit is performed when one is dropped.

Standards

Permissions

For DROP DBSPACE, must have either DBA or SPACE ADMIN authority and must be the only connection to the database.

For others, must be the owner of the object, or have DBA authority.

Global temporary tables cannot be dropped unless all users that have referenced the temporary table have disconnected.

For DROP INDEX, non-DBA users must provide a fully-qualified index name to drop an index on a base table owned by the DBA. DBA or users with the appropriate privileges can drop an index on tables that are owned by non-DBA users without using a fully-qualified name.

See also

ALTER DBSPACE statement

ALTER TABLE statement

CREATE DBSPACE statement

CREATE DOMAIN statement

CREATE EVENT statement

CREATE INDEX statement

CREATE MESSAGE statement [T-SQL]

CREATE PROCEDURE statement

CREATE TABLE statement

CREATE VIEW statement

sp_iqdbspace procedure in Chapter 7, “System Procedures” in Reference: Building Blocks, Tables, and Procedures

Chapter 5, “Working with Database Objects” in the System Administration Guide: Volume 1