You can add or modify columns in sql server using simple queries given below:
Adding a Column to a table:
ALTER TABLE Table_Name ADD NewColumnName CHAR(50) DEFAULT '' NOT NULL
MODIFYING A COLUMN IN A TABLE:
ALTER TABLE Table_Name ALTER COLUMN Table_Column_Name VARCHAR(50) NULL
Below are the points which you need to consider before altering table column:
- Reducing length of column for eg. changing length of column from varchar(50) to varchar(20) will lead to data loss ie. data will be truncated. You should be aware of impact on data after altering table column.
- You cannot alter column which is a primary key.