How is the “alter table” command used in Oracle?

The ALTER TABLE statement in Oracle is used to modify the structure of an existing table, such as adding, modifying or deleting columns, changing table constraints, altering storage options, etc. Common uses include:

  1. Add a column to the table: ALTER TABLE table_name ADD column_name data_type;
  2. Change the data type of a column: ALTER TABLE table_name MODIFY column_name new_data_type;
  3. Change the name of a column: ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;
  4. Delete a column: ALTER TABLE table_name DROP COLUMN column_name;
  5. Add a primary key constraint: ALTER TABLE table_name ADD PRIMARY KEY (column_name);
  6. Add a foreign key constraint to the table by using the following SQL statement: ALTER TABLE table_name ADD FOREIGN KEY (column_name) REFERENCES other_table(column_name);
  7. Change the table name: ALTER TABLE old_table_name RENAME TO new_table_name;
  8. Change the storage options of a table: ALTER TABLE table_name STORAGE (parameter);

In short, the ALTER TABLE statement can be used to make various structural changes to a table.

bannerAds