How to Change All Sql Columns of One DataType into Another

后端 未结 3 1821
失恋的感觉
失恋的感觉 2020-12-11 04:37

I have a database (Sql Server 2005) where there are dozens of tables, each of which has a number of columns (on average 10-20) with da

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 05:04

    You can easily find them, using:

    select 'alter table ' + quotename(o.name) + ' alter column ' + quotename(c.name) + ' varchar(250); '
    from sys.columns c
      join
      sys.objects o
      on o.object_id = c.object_id
    where o.type = 'U'
    and c.user_type_id = 231
    and c.max_length = -1
    

    So now just grab the results of your query and run it.

    Rob

提交回复
热议问题