13.修改数据库的排序规则:
select distinct collationid from dbo.syscolumns
select * from dbo.syscolumns where collationid=53251 --Chinese_Taiwan_Stroke_CI_AS
select * from dbo.syscolumns where collationid=53284 --Chinese_PRC_CI_AS
EXEC sp_configure 'allow updates',1 RECONFIGURE WITH OVERRIDE
update dbo.syscolumns set collationid=53284 where collationid=53251
EXEC sp_configure 'allow updates',0 RECONFIGURE WITH OVERRIDE
go
declare tb cursor for
SELECT sql='alter table ['+d.name
+'] alter column ['+a.name+'] '+b.name
+ '('+cast(a.length*2 as varchar)+')'
+' collate Chinese_PRC_CS_AS'
FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
where
b.name like '%char'
and
not exists(SELECT 1 FROM sysobjects where xtype='PK' and name in (
SELECT name FROM sysindexes WHERE indid in(
SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
))) --主键不能修改
order by d.name,a.name
declare @sql varchar(1000)
open tb
fetch next from tb into @sql
while @@fetch_status = 0
begin
exec(@sql)
fetch next from tb into @sql
end
close tb
deallocate tb
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_killspid]
GO
declare #tb cursor for
select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
open #tb
fetch next from #tb into @spid
while @@fetch_status=0
begin
exec('kill '+@spid)
fetch next from #tb into @spid
end
close #tb
deallocate #tb
go