ALTER

SQL ALTER Keyword

ALTER TABLE

The ALTER TABLE command is used to add, delete, or modify columns in a table. It can also be used to add and delete various constraints in a table.

Tutorials dojo strip

SQL ALTER Syntax – Add Column

SQL

SQL ALTER Example – Add Column

Add a middle_name column to the Patients table:

SQL

SQL ALTER Syntax – Drop Column

SQL

SQL ALTER Example – Drop Column

Remove the middle_name column from the Patients table:

SQL

ALTER COLUMN

The ALTER COLUMN command is used to change the data type of a column in a table.

SQL ALTER Syntax – Alter Column Data Type

SQL

Note: Note: SQLite (our playground) does not support changing a column’s data type directly using ALTER COLUMN. Instead, you must:

1. Rename the new table.

    2. Create a new table with the desired schema.

    3. Copy the data from the old table.

    4. Drop the old table.

    SQL ALTER Example – Alter Column Data Type

    Change the data type of the contact_number column in the Patients table to a longer VARCHAR:

    SQL

    Note: This will not work in our playground.

    SQL ALTER Labs

    Tutorials dojo strip