SQL: DROP USER, TABLE, COLUMN, DATA
DROP USER
PurposeUse the
DROP
USER
statement to remove a database user and optionally remove the user's objects.When you drop a user, Oracle Database also purges all of that user's schema objects from the recycle bin.
Caution: Do not attempt to drop the users
SYS
or SYSTEM
. Doing so will corrupt your database.Prerequisites
You must have the
DROP
USER
system privilege.Syntax
drop_user::=

user
Specify the user to be dropped. Oracle Database does not drop users whose schemas contain objects unless you specify
CASCADE
or unless you first explicitly drop the user's objects.CASCADE
Specify
CASCADE
to drop all objects in the user's schema before dropping the user. You must specify this clause to drop a user whose schema contains any objects.- If the user's schema contains tables, then Oracle Database drops the tables and automatically drops any referential integrity constraints on tables in other schemas that refer to primary and unique keys on these tables.
- If this clause results in tables being dropped, then the database also drops all domain indexes created on columns of those tables and invokes appropriate drop routines.
DROP TBALE[ORACLE SQL]
drop table table_name;
drop table table_name cascade constraints;
drop table table_name purge;
The drop table command moves a table into the recycle bin unless purge was also specified.
purge
Normally, a table is moved into the recycle bin (as of Oracle 10g), if it is dropped. However, if the purge modifier is specified as well, the table is unrecoverably (entirely) dropped from the database.
cascade constraints
Deletes all foreign keys that reference the table to be dropped, then drops the table.
Dropping Columns
Now you can mark a column as unused (logical delete) or delete it completely (physical delete).
Logical Delete
On large tables the process of physically removing a column can be very time and resource consuming. For this reason you may decide to logically delete it.
ALTER TABLE table_name SET UNUSED (column_name); ALTER TABLE table_name SET UNUSED (column_name1, column_name2);
Once this is done the columns will no longer be visible to the user. If at a later date you have time to physically delete the columns this can be done using the following.
ALTER TABLE table_name DROP UNUSED COLUMNS;
On large tables you can reduce the amount of undo logs accumulated by using the CHECKPOINT option which forces a checkpoint after the specified number of rows have been processed.
ALTER TABLE table_name DROP UNUSED COLUMNS CHECKPOINT 250;
The
DBA_UNUSED_COL_TABS
view can be used to view the number of unused columns per table.Physical Delete
To physically drop a column you can use one of the following syntaxes, depending on whether you wish to drop a single or multiple columns.
ALTER TABLE table_name DROP COLUMN column_name; ALTER TABLE table_name DROP (column_name1, column_name2);
Dropping a column from a table will cause all unused columns in that table to be dropped at the same time.
DELETE Statement
Description
The Oracle DELETE statement is used to delete a single record or multiple records from a table in Oracle.
Syntax
The syntax for the DELETE statement in Oracle/PLSQL is:
DELETE FROM table [WHERE conditions];
Parameters or Arguments
- table
- The table that you wish to delete records from.
- WHERE conditions
- Optional. The conditions that must be met for the records to be deleted. If no conditions are provided, then all records from the table will be deleted.
Comments
Post a Comment