Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens in Oracle when I drop a column?

Tags:

oracle

What are the various things that happen when I drop a column from a filled table. In all_tab_columns, does the column_id of other columns get reset?

like image 799
trinity Avatar asked Nov 01 '10 06:11

trinity


People also ask

What happens when you drop a column in SQL?

No data gets modified. The column metadata gets marked as 'deleted' and will be ignored.

Can we drop a column with data in Oracle?

To drop a column in an existing table in Oracle, here is the syntax: ALTER TABLE table_name DROP COLUMN column_name; To drop multiple columns in an existing table: ALTER TABLE table_name DROP (column_name1, column_name2,…);

What happens when a table is dropped in Oracle?

Dropping a table removes the table definition from the data dictionary. All rows of the table are no longer accessible. All indexes and triggers associated with a table are dropped. All views and PL/SQL program units dependent on a dropped table remain, yet become invalid (not usable).

How do you drop a column in Oracle?

Use the COMMENT statement to add a comment about a table, view, materialized view, or column into the data dictionary. To drop a comment from the database, set it to the empty string ' '.


2 Answers

alter table drop column

will actually visit each block and remove the column data - and that's an expensive thing to do for a large table.

You might find it more prudent to issue:

alter table set unused

which just flags the column as "gone" in the dictionary. If you then still need to reclaim that space, you can schedule an "alter table drop unused" at a quiet time

like image 31
Connor Avatar answered Sep 22 '22 18:09

Connor


The actions will include at least the following:

  • The data stored in that column is lost.
  • Views referencing that column are invalidated - but (according to Gary - thanks!) they're not dropped; they stay invalid until revised to work with the modified schema.
  • Stored procedures referencing that column are invalidated - same caveat.
  • The column ID numbers of following columns will be reset.
  • Permissions granted on the column will be removed.
  • Indexes referencing that column will be dropped.
like image 59
Jonathan Leffler Avatar answered Sep 22 '22 18:09

Jonathan Leffler