简体中文的排序规则名称是:Chinese_PRC_CI_AS,
繁体中文的排序规则名称则是:Chinese_Taiwan_Stroke_CI_AS
更改数据库定序:
ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE DatabaseName COLLATE Chinese_Taiwan_Stroke_CI_AS
ALTER DATABASE DatabaseName SET MULTI_USER WITH ROLLBACK IMMEDIATE
-- 修改資料庫定序為 Chinese_PRC_CI_AS
ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE DatabaseName COLLATE Chinese_PRC_CI_AS;
ALTER DATABASE DatabaseName SET MULTI_USER;
-- 修改資料表定序為 Chinese_PRC_CI_AS
ALTER TABLE tableName ALTER COLUMN colName nvchar(length)
COLLATE
Chinese_PRC_CI_AS;
要注意的是,修改資料庫的定序設定,並不會變更該資料庫內既有物件的定序設定
循環修改資料庫表中各字段的定序:
首先執行
declare @table_name nvarchar(50)
declare @Col_name nvarchar(50)
declare @DATA_TYPE nvarchar(50)
declare @MAX_LENGTH nvarchar(50)
declare cu cursor for
SELECT
a.TABLE_NAME as 表格名稱,
b.COLUMN_NAME as 欄位名稱,
b.DATA_TYPE as 資料型別,
b.CHARACTER_MAXIMUM_LENGTH as 最大長度
FROM
INFORMATION_SCHEMA.TABLES a
LEFT JOIN INFORMATION_SCHEMA.COLUMNS b ON ( a.TABLE_NAME=b.TABLE_NAME )
WHERE
TABLE_TYPE='BASE TABLE'
ORDER BY
a.TABLE_NAME, ordinal_position
open cu
fetch next from cu into @table_name,@Col_name,@DATA_TYPE,@MAX_LENGTH
begin tran
WHILE @@FETCH_STATUS = 0
begin
if @DATA_TYPE ='char' or @DATA_TYPE ='varchar' or @DATA_TYPE ='nchar' or @DATA_TYPE ='nvarchar'
print 'ALTER TABLE ' +@table_name+ ' ALTER COLUMN ['+ @Col_name + ']'
+@DATA_TYPE+ '('+@MAX_LENGTH+') COLLATE Chinese_Taiwan_Stroke_CI_AS;' -- Chinese_PRC_CI_AS
if @DATA_TYPE ='text' or @DATA_TYPE ='ntext'
print 'ALTER TABLE ' +@table_name+ ' ALTER COLUMN ['+ @Col_name + ']'
+@DATA_TYPE+ ' COLLATE Chinese_Taiwan_Stroke_CI_AS;' -- Chinese_PRC_CI_AS
fetch next from cu into @table_name,@Col_name,@DATA_TYPE,@MAX_LENGTH
end
close cu
deallocate cu
if @@error=0
begin
commit tran
end
else
begin
rollback tran
end
然后執行上面產生的SQL
declare @Col_name nvarchar(50)
declare @DATA_TYPE nvarchar(50)
declare @MAX_LENGTH nvarchar(50)
declare cu cursor for
SELECT
a.TABLE_NAME as 表格名稱,
b.COLUMN_NAME as 欄位名稱,
b.DATA_TYPE as 資料型別,
b.CHARACTER_MAXIMUM_LENGTH as 最大長度
FROM
INFORMATION_SCHEMA.TABLES a
LEFT JOIN INFORMATION_SCHEMA.COLUMNS b ON ( a.TABLE_NAME=b.TABLE_NAME )
WHERE
TABLE_TYPE='BASE TABLE'
ORDER BY
a.TABLE_NAME, ordinal_position
open cu
fetch next from cu into @table_name,@Col_name,@DATA_TYPE,@MAX_LENGTH
begin tran
WHILE @@FETCH_STATUS = 0
begin
if @DATA_TYPE ='char' or @DATA_TYPE ='varchar' or @DATA_TYPE ='nchar' or @DATA_TYPE ='nvarchar'
print 'ALTER TABLE ' +@table_name+ ' ALTER COLUMN ['+ @Col_name + ']'
+@DATA_TYPE+ '('+@MAX_LENGTH+') COLLATE Chinese_Taiwan_Stroke_CI_AS;' -- Chinese_PRC_CI_AS
if @DATA_TYPE ='text' or @DATA_TYPE ='ntext'
print 'ALTER TABLE ' +@table_name+ ' ALTER COLUMN ['+ @Col_name + ']'
+@DATA_TYPE+ ' COLLATE Chinese_Taiwan_Stroke_CI_AS;' -- Chinese_PRC_CI_AS
fetch next from cu into @table_name,@Col_name,@DATA_TYPE,@MAX_LENGTH
end
close cu
deallocate cu
if @@error=0
begin
commit tran
end
else
begin
rollback tran
end
然后執行上面產生的SQL