In SQL, the ALTER TABLE statement is used to modify an existing table.
It allows us to "add", "modify", or "drop" columns, change data types, add or remove indexes, and make other structural changes to a table.
We can add a new column to an existing table using the ADD keyword:
ALTER TABLE table_name ADD COLUMN new_column_name data_type;
ALTER TABLE products ADD COLUMN product_name VARCHAR(50);
We can modify the data type or other properties of an existing column using the MODIFY keyword:
ALTER TABLE table_name MODIFY COLUMN column_name new_data_type;
ALTER TABLE products MODIFY COLUMN product_name VARCHAR(200);
We can rename an existing column using the CHANGE keyword:
ALTER TABLE table_name CHANGE old_column_name new_column_name data_type;
ALTER TABLE products CHANGE price product_price VARCHAR(50);
We can remove a column from a table using the DROP keyword:
ALTER TABLE table_name DROP COLUMN column_name;
ALTER TABLE products DROP COLUMN category;