SQL Tutorial – ALTER TABLE – ADD and DROP a column.

You want to add a new column or delete a column from a table or You want to add multiple columns or delete multiple columns from a table in a single query.

Solution –

Add a column in a Table –

To add a new column in a table, we can use the ALTER TABLE ADD statement.

Syntax –

ALTER TABLE table_name

ADD new_column_name column_definition

Let’s add a new column address in the actors_info table.

ALTER TABLE actors_info
ADD address  VARCHAR(80) 

Add Multiple columns in a Table –

To add multiple columns in a table, we can just use the above query and add more column names and their definitions one after another.

ALTER TABLE actors_info
ADD Phone INT,
ADD Awards INT

Delete a Column from a Table –

To drop or delete a column from a table, we can use the ALTER TABLE DROP COLUMN statement.

Syntax –

ALTER TABLE table_name

DROP COLUMN cloumn_name

Let’s drop the address column from the actors_info table.

ALTER TABLE actors_info
DROP COLUMN address

Delete Multiple columns from a table –

To delete multiple columns from a table, we can just use the above query and add more DROP COLUMN column_name one after another.

ALTER TABLE actors_info
DROP COLUMN Phone,
DROP COLUMN Awards

Related Post – ALTER TABLE- Rename Columns and Table names.

If you like this post then please share it with others and subscribe to our blog to get better at SQL.

Rating: 1 out of 5.

Leave a Reply