Home

Microsoft SQL Server Topics: Changing the Data Type of a Column

       

Visually Changing the Data Type of a Column

To visually change the data type of a column, open the table in Design View, locate the column under Column Name, and change its type under Data Type.

Changing the Data Type of a Column Using SQL Code

The formula to programmatically change the data type of a column is:

ALTER TABLE TableName
ALTER COLUMN ColumnName NewDataType

Here is an example:

CREATE SCHEMA HumanResources;
GO
CREATE TABLE HumanResources.Genders
(
    Gender char
);
GO
ALTER TABLE HumanResources.Genders
ALTER COLUMN Gender tinyint;
GO

Home Copyright © 2003-2013, FunctionX