100 Days of SQL


Day 51 – SQL ALTER COLUMN Keyword

SQL ALTER COLUMN keyword is used to modify the structure of a column in an existing database table. The ALTER COLUMN statement is part of the Data Definition Language (DDL) in SQL and can be used to change the data type, size, nullability, and other properties of a column.

The syntax of the ALTER COLUMN statement is as follows:

ALTER TABLE table_name
ALTER COLUMN column_name new_data_type [NULL | NOT NULL]

Here, table_name is the name of the table containing the column to be modified, column_name is the name of the column to be modified, new_data_type is the new data type of the column, and NULL or NOT NULL is used to specify whether the column allows NULL values or not.

For example, the following SQL statement modifies the data type of the age column in the students table to INT:

ALTER TABLE students

Note that the ALTER COLUMN statement can also be used to add or drop default values, add or drop constraints, and perform other modifications to the column’s structure. The exact syntax may vary depending on the specific database management system being used.