DROP Statement

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
| MESSAGE message-number
| TABLE [ IF EXISTS ]  [ owner.]table-name
| VIEW [ IF EXISTS ]  [ owner.]view-name
| MATERIALIZED VIEW [ IF EXISTS ]  [ owner.]view-name
| PROCEDURE [ IF EXISTS ]  [ owner.]procedure-name
| FUNCTION [ IF EXISTS ]  [ owner.]function-name }

Examples

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.

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, 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 IDENTITY_INSERT to ' ' (an empty string), or set 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.

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.

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

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

  • SQL—ISO/ANSI SQL compliant.

  • Sybase—Supported by Adaptive Server Enterprise.

Permissions

DBSPACE clause – Requires the DROP ANY OBJECT system privilege and user must be the only connection to the database.

DOMAIN clause – Requires one of:
  • DROP DATATYPE system privilege.
  • DROP ANY OBJECT system privilege.
  • You own the object.
FUNCTION clause – Requires one of:
  • DROP ANY PROCEDURE system privilege.
  • DROP ANY OBJECT system privilege.
  • You own the function.
INDEX clause – Requires one of:
  • DROP ANY INDEX system privilege.
  • DROP ANY OBJECT system privilege.
  • REFERENCE privilege on the underlying table being indexed.
  • You own the underlying table being indexed.
DBA or users with the appropriate privilege can drop an index on tables that are owned other users without using a fully-qualified name. All other users must provide a fully-qualified index name to drop an index on a base table owned by the DBA.
MATERIALIZED VIEW clause – Requires one of:
  • DROP ANY MATERIALIZED VIEW system privilege.
  • DROP ANY OBJECT system privilege.
  • You own the materialized view.
PROCEDURE clause – Requires one of:
  • DROP ANY PROCEDURE system privilege.
  • DROP ANY OBJECT system privilege.
  • You own the procedure.
TABLES clause – Requires one of:
  • DROP ANY TABLE system privilege.
  • DROP ANY OBJECT system privilege.
  • You own the table.
Global temporary tables cannot be dropped unless all users that have referenced the temporary table have disconnected.
VIEW clause – Requires one of:
  • DROP ANY VIEW system privilege.
  • DROP ANY OBJECT system privilege.
  • You own the view.
All other clauses – Requires one of:
  • DROP ANY OBJECT system privilege.
  • You own the object.