SQL Alter table statement

Create Table

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

Add Columns

To add a column in a table, we will use the following syntax:

syntax:

ALTER TABLE table_name
ADD column_name datatype

Example:

ALTER TABLE articles
ADD author varchar(30);

Delete Columns

To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column):

syntax:

ALTER TABLE table_name
DROP COLUMN column_name

Example:

ALTER TABLE articles
DROP COLUMN author;

Modify data type

To change the data type of a column in a table, use the following syntax:

syntax:

ALTER TABLE table_name
ALTER COLUMN column_name datatype

Example:

ALTER TABLE articles
ALTER COLUMN author varchar(30) ;

Bookmark This Page

Link Partners