Altering a Table

SQL Server 2005 allows existing tables to be modified in several ways. Using the ALTER TABLE command, you can make the following types of changes to an existing table:

  • Change the data type or NULL property of a single column

  • Add one or more new columns, with or without defining constraints for those columns

  • Add one or more constraints

  • Drop one or more constraints

  • Drop one or more columns

  • Enable or disable one or more constraints (applies only to CHECK and FOREIGN KEY constraints)

  • Enable or disable one or more triggers

Changing a Data Type

By using the ALTER COLUMN clause of ALTER TABLE, you can modify the data type or NULL property of an existing column. But be aware of the following restrictions:

  • The modified column can’t be a text, image, ...

Get Inside Microsoft® SQL Server™ 2005, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.