SQL Server排序規(guī)則的應用
作者:佚名
SQL Server數(shù)據(jù)庫中的排序規(guī)則指的是排序規(guī)則指定表示每個字符的位模式以及存儲和比較字符所使用的規(guī)則,下面就讓我們來了解一下排序規(guī)則的應用。
SQL Server排序規(guī)則在SQL數(shù)據(jù)庫中都有哪些應用呢?下面就為您介紹SQL Server排序規(guī)則的應用方面的知識,如果您感興趣的話,不妨一看。
SQL Server排序規(guī)則的應用:
sql server提供了大量的windows和sqlserver專用的排序規(guī)則,但它的應用往往被開發(fā)人員所忽略。其實它在實踐中大有用處。
例1:讓表name列的內(nèi)容按拼音排序:
- create table #t(id int,name varchar(20))
- insert #t select 1,中
- union all select 2,國
- union all select 3,人
- union all select 4,阿
- select * from #t order by name collate chinese_prc_cs_as_ks_ws
- drop table #t
/*結(jié)果:
- id name
- ----------- --------------------
- 4 阿
- 2 國
- 3 人
- 1 中
- */
例2:讓表name列的內(nèi)容按姓氏筆劃排序:
- create table #t(id int,name varchar(20))
- insert #t select 1,三
- union all select 2,乙
- union all select 3,二
- union all select 4,一
- union all select 5,十
- select * from #t order by name collate chinese_prc_stroke_cs_as_ks_ws
- drop table #t
/*結(jié)果:
- id name
- ----------- --------------------
- 4 一
- 2 乙
- 3 二
- 5 十
- 1 三
- */
【編輯推薦】
責任編輯:段燃
來源:
互聯(lián)網(wǎng)