|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Ordering a heapI have created and populated a table with no indexes and would like to order
the data prior to creating an index. I realize I can use "order by" in my queries to get my output the way I want it, but I was wondering if: 1) is there is a way to order/sort the data in a table based on the values in a field? 2) does it make sense to do so? Can anyone help me with these questions? Thanks in advance, Raul >I have created and populated a table with no indexes and would like to This may sound kind of naive of me, but what about this:>order > the data prior to creating an index. I realize I can use "order by" in my > queries to get my output the way I want it, but I was wondering if: > 1) is there is a way to order/sort the data in a table based on the values > in a field? 2) does it make sense to do so? Create a clustered index on the column(s) you wish the data to be sorted by. Then the data will all be in that order. Then drop your clustered index and create your regular ones. But it brings to my mind two questions: 1. wouldn't it be better to leave the clustered index and create your nonclustered ones on top of it? 2. I don't think the fragmentation or ordering of heap index pages is affected by the data being initially ordered or not. -- Peace & happy computing, Mike Labosh, MCSD "When you kill a man, you're a murderer. Kill many, and you're a conqueror. Kill them all and you're a god." -- Dave Mustane 1. Unless you are using ORDER BY, there is no guarantee.
2. Not really. -- Anith 1) No there isn't
2) No it doesn't Further to 1), although a clustered index stores rows within leaf pages "in order" the idea of "sorting the data in the table" is still meaningless because the clustered index ordering isn't directly exposed to the user. Your subject indicates that you aren't using a clustered index anyway. Get used to the idea that a table is a logically unordered set of rows - it's that fact, among others, that makes your database the powerful tool it is. -- David Portas SQL Server MVP -- Thanks for the help,
Raul Show quote "Raul" wrote: > I have created and populated a table with no indexes and would like to order > the data prior to creating an index. I realize I can use "order by" in my > queries to get my output the way I want it, but I was wondering if: > 1) is there is a way to order/sort the data in a table based on the values > in a field? 2) does it make sense to do so? > > Can anyone help me with these questions? > > Thanks in advance, > Raul This ought to be fun :)
You have no control over how the data is physically stored in a SQL database. The dbms can store data any way it chooses. It does not have to be physically contiguous. SQL is declarative. You tell it what you want done, not how to do it. Come to think of it, I am declarative too :) Having said that, you might want to look up Clustered Indexes in BOL. Payson Raul wrote: Show quote > I have created and populated a table with no indexes and would like to order > the data prior to creating an index. I realize I can use "order by" in my > queries to get my output the way I want it, but I was wondering if: > 1) is there is a way to order/sort the data in a table based on the values > in a field? 2) does it make sense to do so? > > Can anyone help me with these questions? > > Thanks in advance, > Raul >> have created and populated a table with no indexes and would like to order the data prior to creating an index. << Let's get back to the basics of an RDBMS. Rows are not records; fieldsare not columns; tables are not files; there is no sequential access or ordering in an RDBMS, so this makes no sense. >> have created and populated a table with no indexes and would like to order the data prior to creating an index. << Let's get back to the basics of an RDBMS. Rows are not records; fieldsare not columns; tables are not files; there is no sequential access or ordering in an RDBMS, so this makes no sense. But to know what way data is stored, you may use undocumented
DBCC PAGE -- Show quoteRegards R.D --Knowledge gets doubled when shared "Raul" wrote: > I have created and populated a table with no indexes and would like to order > the data prior to creating an index. I realize I can use "order by" in my > queries to get my output the way I want it, but I was wondering if: > 1) is there is a way to order/sort the data in a table based on the values > in a field? 2) does it make sense to do so? > > Can anyone help me with these questions? > > Thanks in advance, > Raul |
|||||||||||||||||||||||