SQL Server排序规则的应用

SQL Server排序规则在SQL数据库中都有哪些应用呢?下面就为您介绍SQL Server排序规则的应用方面的知识,如果您感兴趣的话,不妨一看。

SQL Server排序规则的应用:

sql server提供了大量的windows和sqlserver专用的排序规则,但它的应用往往被开发人员所忽略。其实它在实践中大有用处。

例1:让表name列的内容按拼音排序:

 
 
 
  1. create table #t(id int,name varchar(20))  
  2. insert #t select 1,中  
  3. union all select 2,国  
  4. union all select 3,人  
  5. union all select 4,阿  
  6.  
  7. select * from #t order by name collate chinese_prc_cs_as_ks_ws   
  8. drop table #t  

/*结果:

 
 
 
  1. id          name                   
  2. ----------- --------------------   
  3. 4           阿  
  4. 2           国  
  5. 3           人  
  6. 1           中  
  7. */ 

例2:让表name列的内容按姓氏笔划排序:

 
 
 
  1. create table #t(id int,name varchar(20))  
  2.  
  3. insert #t select 1,三  
  4. union all select 2,乙  
  5. union all select 3,二  
  6. union all select 4,一  
  7. union all select 5,十  
  8. select * from #t order by name collate chinese_prc_stroke_cs_as_ks_ws   
  9. drop table #t  

/*结果:

 
 
 
  1. id          name                   
  2. ----------- --------------------   
  3. 4           一  
  4. 2           乙  
  5. 3           二  
  6. 5           十  
  7. 1           三  
  8. */  

 

 

 

 

【编辑推荐】

带您了解SQL Server标识列

SQL Server添加列及删除列

SQL SERVER TOC分页的实现方法

SQL Server系统表的应用

SQL Server UPDATE语句的用法

THE END