--修改数据库表字段排序规则:
select a.name,a.max_length,a.user_type_id,a.collation_name,
'alter table ['+c.name+'] alter column '+a.name +' '
+
case
when a.user_type_id=231 then 'nvarchar('+ case when a.max_length=-1 then 'max' else cast(a.max_length/2 as varchar(100)) end+')'
else 'varchar('+case when a.max_length=-1 then 'max' else cast(a.max_length as varchar(100)) end+')' end
+
' COLLATE Chinese_PRC_CI_AS'
from sys.columns a
left join sys.objects c on a.OBJECT_ID=c.OBJECT_ID
where c.type='U' and c.name = 'User'
and a.user_type_id in (167,231) -- --167:varchar --231:nvarchar
GO