Script to alter data type

  • I want to change all columns which match a naming convention to be of int datatype. Some of them will be nullable some not, some may be in FK relation. I want to change the data type to int from what ever it was whilst leaving all other properties of the column in place.

     

    Anyone got a script which will do this?

    www.sql-library.com[/url]

  • or any pointers of course

    www.sql-library.com[/url]

  • Just a start... 'cause I don't think you can alter the datatype when in a fk relation unless you change both, which requires dropping the relation, altering the columns and then recreating the relation.

     

    Select object_name(C.id) as TableName, C.Name as ColName from dbo.SysColumns C where C.Name = 'YourColname'

    That will at least get you a list to get started.

     

     

    Also I must point out that this operation requires a lot more preparation that it seems because of the implications of changing all the objects that reffer to this column.

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

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