数据库
首页 > 数据库> > MSSQL修改指定表列的排序规则

MSSQL修改指定表列的排序规则

作者:互联网

--修改数据库表字段排序规则:


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

标签:varchar,name,--,max,表列,length,排序,type,MSSQL
来源: https://www.cnblogs.com/cheua/p/15050034.html