📜  oracle alter table - SQL (1)

📅  最后修改于: 2023-12-03 14:44:55.208000             🧑  作者: Mango

Oracle Alter Table - SQL

In Oracle SQL, the ALTER TABLE statement is used to add, modify or delete columns in an existing table. This statement allows programmers to efficiently manage their database tables.

Adding a column

To add a column to an existing table, the ALTER TABLE statement can be used in the following format:

ALTER TABLE table_name ADD (column_name data_type);

For example:

ALTER TABLE employees ADD (phone_number VARCHAR2(20));

This statement will add a new column called "phone_number" to the "employees" table with a data type of VARCHAR2 and a maximum length of 20 characters.

Modifying a column

To modify an existing column in a table, the ALTER TABLE statement can be used in the following format:

ALTER TABLE table_name MODIFY (column_name new_data_type);

For example:

ALTER TABLE employees MODIFY (phone_number NUMBER(10));

This statement will modify the "phone_number" column in the "employees" table, changing the data type from VARCHAR2 to NUMBER with a maximum length of 10 digits.

Deleting a column

To delete an existing column in a table, the ALTER TABLE statement can be used in the following format:

ALTER TABLE table_name DROP COLUMN column_name;

For example:

ALTER TABLE employees DROP COLUMN phone_number;

This statement will delete the "phone_number" column from the "employees" table.

Conclusion

In conclusion, the ALTER TABLE statement is a powerful tool for managing Oracle SQL database tables. It allows programmers to add, modify and delete columns as required, making it an essential part of any database management system.