SQL Server - SQL Table Basics - Altering/Adding Columns

Adding column

You can add new columns to an existing table. .

ALTER TABLE [dbo].[phone]
ADD   inactive_date DATETIME NULL  


Alter column

You can add modify an existing column

ALTER TABLE [dbo].[person]


Considerations for altering a column

  • Reducing precision (example, going from CHAR(20) to CHAR(15)) can cause data truncation and should be avoided unless you are absolutely sure their will be no impact to the data.
  • Changing data types should typically be avoided. There are exceptions to this. For example, changing a CHAR(20) to a VARCHAR(20) on columns where the average storage length is 10 can save disk space.

Alter columns - No Can Do

  • You cannot directly alter a a column that is part of the primary key