想要在ALPHABETICAL ORDER of Names上对表格进行排序 [英] want to sort my table on the ALPHABETICAL ORDER of Names

查看:119
本文介绍了想要在ALPHABETICAL ORDER of Names上对表格进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张包含3个字段ID,名称和卷号的表格



假设为1,Santhosh 1

2 Govind 2

3 Nikhil 3



我的问题是,当我插入新数据时,说Divya卷4号,我想排序我在名称的字母顺序上的表格。也就是说,我的输出应该如下..



名称卷号



Divya 1

Govind 2

Nikhil 3

Santhosh 4



我怎样才能做到这一点sql server 2008 ???有人可以帮我吗????

谢谢,

Rahul ..

i have a table with 3 fields ID, Name and Roll Number

lets suppose it as, 1 Santhosh 1
2 Govind 2
3 Nikhil 3

My Question is, When I Insert a new Data,say Divya with Roll Number 4, i want to sort my table on the ALPHABETICAL ORDER of Names. That is, my output should be as follows..

Name Roll Number

Divya 1
Govind 2
Nikhil 3
Santhosh 4

How can i do this in sql server 2008??? Can anybody help me please????
Thanks,
Rahul..

推荐答案

I DON' 我想是的。插入

时不可能,但你可以选择上面的记录,你可以这样做



I DON''T think so. its not possible while insert
but you can do while select the above record you can do it like this

create table Satheesh(fieldid int identity(1,1), names varchar(20), rollno int)



insert into Satheesh values('Santhosh',1)
insert into Satheesh values('Govind',2)
insert into Satheesh values('Nikhil',3)
insert into Satheesh values('divya',4)

select row_number() over (order by names) as rollno, names  from satheesh
order by names







结果






result

rollno               names
-------------------- --------------------
1                    divya
2                    Govind
3                    Nikhil
4                    Santhosh

(4 row(s) affected)


根据我对SQL服务器表的理解,数据存储在基于聚簇索引的B-Tree数据结构中。因此,默认情况下,记录由聚簇索引列排序。在这种情况下,您可能需要更改聚簇索引并检查结果。
As per my understanding in SQL server table data is stored in B-Tree data structure which is based on your clustered index. So record by default is ordered by your clustered index column. In this case you may need change your clustered index and check the result.


这篇关于想要在ALPHABETICAL ORDER of Names上对表格进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆