Changing column datatype database wide

  • Hi There,

    Is there a way to go thru all of the user tables in a system and change a all column datatypes from one type to another? Need to change all REAL to DECIMAL(Scale 2) on a number of tables and while it could be done manually, scripting it would seem easier.

    I can find all of the occurances of REAL datatypes with this:

    SELECT

    table_name=sysobjects.name,

    column_name=syscolumns.name,

    data_type=syscolumns.xtype

    FROM

    sysobjects inner JOIN syscolumns ON sysobjects.id = syscolumns.id

    inner join systypes on syscolumns.xtype=systypes.xusertype

    where sysobjects.xtype='U' and syscolumns.xtype=59

    My question is I guess do I need to write a script that goes thru and does ALTER TABLE/ALTER COLUMN statements or can I just go thru and change the value directly in syscolumns.xtype?

    Regards,

    Chris

  • I would highly recommend NOT changing data directly in system tables (you would need to set configuration settings to do so anyway). Write a script that does ALTER TABLE for each column. That's a much safer bet.

Viewing 2 posts - 1 through 1 (of 1 total)

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