Add Columns to existing table where I need the column to be?!

  • thatok (12/22/2008)


    You can recreate the table with a select statement.

    SELECT AreaID, RegionID, '' as NewField,Area, AreaCode

    Into Areas_Modified

    FROM Areas

    But then you will need to use your alter statement to modify that column to your required data type because on creation it will be defaulted to varchar(1).

    after that don't forget to drop your old table so that you can replace with the new one.

    You won't need an alter statement if you convert the '' to the proper data type as part of the select statement - as in:

    SELECT AreaID, RegionID, convert(varchar(15),null) as NewField, Area, AreaCode

    Into Areas_Modified

    FROM Areas

Viewing post 16 (of 15 total)

You must be logged in to reply to this topic. Login to reply