ALTER TABLE

With ALTER we can modify an existing table. We can add, delete, edit fields in the table.

Structure:

add column:

ALTER TABLE table_name
ADD column_name data_type;

drop column:

ALTER TABLE table_name
DROP column_name data_type;

Oracle, MYSQL:

ALTER TABLE table_name
MODIFY column_name data_type;

SQL Server, PostrgreSQL:

ALTER TABLE table_name
ALTER COLUMN column_name TYPE data_type;

Example1:

We have table with this data:

Table Staff

STAFFID STAFF_NAME SUPERVISORID
1 Frank 3
2 Helena 3
3 Julia -
4 Thomas 2
ALTER TABLE Staff
ADD TestColumn NUMBER;

Leave a Comment

Your email address will not be published. Required fields are marked *