Home All Groups Group Topic Archive Search About
Author
20 Oct 2005 8:01 PM
Raul
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

Author
20 Oct 2005 8:10 PM
Mike Labosh
>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?

This may sound kind of naive of me, but what about this:

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
Author
20 Oct 2005 8:12 PM
Anith Sen
1. Unless you are using ORDER BY, there is no guarantee.
2. Not really.

--
Anith
Author
20 Oct 2005 8:14 PM
David Portas
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
--
Author
20 Oct 2005 8:19 PM
Raul
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
Author
20 Oct 2005 9:02 PM
Payson
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
Author
21 Oct 2005 2:30 AM
--CELKO--
>>  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; fields
are not columns; tables are not files; there is no sequential access or
ordering in an RDBMS, so this makes no sense.
Author
21 Oct 2005 2:30 AM
--CELKO--
>>  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; fields
are not columns; tables are not files; there is no sequential access or
ordering in an RDBMS, so this makes no sense.
Author
21 Oct 2005 4:47 AM
R.D
But to know what way data is stored, you may use undocumented
DBCC PAGE
--
Regards
R.D
--Knowledge gets doubled when shared


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

AddThis Social Bookmark Button