0

I'm using SQL Server Management Studio and I have a table with a primary key which is a combination of letters and numbers.

My co-woker inserted all primary keys and now she wants to start inserting data, so she asked me if I can resave the data so that the table is sorted by its primary key. But I was thinking that it should be already sorted??

So, my question is ...

When I right-click the table and select "Edit Top XXX Rows", is the table already sorted by its primary key?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kabichan
  • 1,063
  • 4
  • 19
  • 49
  • 2
    if primary key is a clustered index, there are good probability of table will be sorted on it, but server does not guarantee it. – shibormot Feb 27 '13 at 00:07

2 Answers2

2

You should be seeing the editable rows, sorted by the clustered index, which is generally the primary key, but could be more. More information on Clustered vs Non-Clustered Indexes can be found in this discussion here.

Also, you can manually change the SQL Select Statement that is being executed in order to present the editable rows. Follow the simple instructions from this blog post, and you will be able to view the rows, ordered by which ever column you desire.

Hope this was helpful!

CSharpie

Community
  • 1
  • 1
CSharpie
  • 51
  • 3
-2

Yes, It will be sorted by primary key only if the primary key is also the CLUSTERING KEY.

Iswanto San
  • 18,263
  • 13
  • 58
  • 79
  • 2
    I'm not the downvoter, but possible reason is that what you saying is not a promise. See here http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/05/20/without-order-by-there-is-no-default-sort-order.aspx – Andrew Savinykh Feb 27 '13 at 00:37