Tutorials
Practical T-SQL
Search
K
Comment on page

Lesson 28. Altering Tables

You can use T-SQL to alter pretty much every aspect of a table. The syntax for doing so changes depending on what aspect of the table you are trying to alter. For the purposes of this tutorial, we will just focus on altering table columns.

Examples

Add A Column
In [ ]:
USE demo
ALTER TABLE Person ADD PhoneNumber NVARCHAR(10)
Change Column Name
In [ ]:
USE demo
EXEC sp_rename 'Person.PhoneNumber', 'NumberOfChildren', 'COLUMN';
Change Column Data Type
In [ ]:
USE demo
ALTER TABLE Person ALTER COLUMN NumberOfChildren INT
Delete A Column
In [ ]:
USE demo
ALTER TABLE Person DROP COLUMN NumberOfChildren