1ALTER TABLE table_name
2ALTER COLUMN column_name datatype;
3
4-- Example
5ALTER TABLE product
6ALTER COLUMN description VARCHAR(250);
1Changes the data type of a table’s column.
2Example: In the ‘users’ table, make the column ‘incept_date’ into a
3‘datetime’ type.
4ALTER TABLE users
5ALTER COLUMN incept_date datetime;
1-- With check if field already exists
2
3IF NOT EXISTS(SELECT 1 FROM sys.columns
4 WHERE Name = N'Email'
5 AND Object_ID = Object_ID(N'dbo.Customers'))
6BEGIN
7 ALTER TABLE Customers
8 ADD Email varchar(255);
9END