Skip to content

Latest commit

 

History

History
86 lines (57 loc) · 3.72 KB

File metadata and controls

86 lines (57 loc) · 3.72 KB
title Modify Columns (Database Engine) | Microsoft Docs
ms.custom
ms.date 03/14/2017
ms.prod sql
ms.prod_service table-view-index, sql-database, sql-data-warehouse, pdw
ms.reviewer
ms.technology table-view-index
ms.topic conceptual
helpviewer_keywords
modifying data types
column data types [SQL Server]
data types [SQL Server], columns
ms.assetid b67b95c5-61ef-4bd8-9a3e-1640eb7583ac
author stevestein
ms.author sstein
monikerRange >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current

Modify Columns (Database Engine)

[!INCLUDEtsql-appliesto-ss2016-all-md]

You can modify the data type of a column in [!INCLUDEssCurrent] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql].

Warning

Modifying the data type of a column that already contains data can result in the permanent loss of data when the existing data is converted to the new type. In addition, code and applications that depend on the modified column may fail. These include queries, views, stored procedures, user-defined functions, and client applications. Note that these failures will cascade. For example, a stored procedure that calls a user-defined function that depends on the modified column may fail. Carefully consider any changes you want to make to a column before making it.

In This Topic

Before You Begin

Security

Permissions

Requires ALTER permission on the table.

Using SQL Server Management Studio

To modify the data type of a column

  1. In Object Explorer, right-click the table with columns for which you want to change the scale and click Design.

  2. Select the column for which you want to modify the data type.

  3. In the Column Properties tab, click the grid cell for the Data Type property and choose a new data type from the drop-down list.

  4. On the File menu, click Savetable name.

Note

When you modify the data type of a column, Table Designer applies the default length of the data type you selected, even if you have already specified another. Always set the data type length for to the desired value after specifying the data type.

Warning

If you attempt to modify the data type of a column that relates to other tables, Table Designer asks you to confirm that the change should be made to the columns in the other tables as well.

Using Transact-SQL

To modify the data type of a column

  1. In Object Explorer, connect to an instance of [!INCLUDEssDE].

  2. On the Standard bar, click New Query.

  3. Copy and paste the following example into the query window and click Execute.

    CREATE TABLE dbo.doc_exy (column_a INT ) ;  
    GO  
    INSERT INTO dbo.doc_exy (column_a) VALUES (10) ;  
    GO  
    ALTER TABLE dbo.doc_exy ALTER COLUMN column_a DECIMAL (5, 2) ;  
    GO  
    

For more information, see ALTER TABLE (Transact-SQL)