change a column in a table from float to nvarchar RRS feed

  • Question

  • I have inherited a table which has a column with the datatype float. Unfortunately, this column (a product code) does not accept values with letters in it. I was told that new product codes will have letters as well as numbers in them and a suggestion to use nvarchar as the new datatype was made.

    Is it possible to change the datatype by just changing the datatype in design? if not can anyone help with how to make this change? this is a very large table and recreating it and re-populating it seems a large task.


    Thursday, August 9, 2012 2:09 AM


All replies

    • Edited by Jackson_1990 Thursday, August 9, 2012 2:21 AM
    • Marked as answer by Iric Wen Thursday, August 16, 2012 9:39 AM
    Thursday, August 9, 2012 2:19 AM
  • You can change from Float to NVARCHAR without any issue. Please do it through ALTER TABLE ALTER COLUMN command. Do not use SSMS Editor as it will drop the table and recreate it.

    Service Delivery & Support Management

    Thursday, August 9, 2012 2:26 AM
  • Hi Luis, if your product codes do not contain Unicode data, you could also look at changing the datatype to varchar as opposed to nvarchar.  The nvarchar data type stores 2 bytes per character as opposed to 1 byte per character with varchar, so you could save a bit of space if needed.

    Sam Lester (MSFT)    

    My Blog

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

    Thursday, August 9, 2012 2:57 AM