Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Order My Data


Order My Data

Author
Message
steve.jacobs
steve.jacobs
SSChasing Mays
SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)

Group: General Forum Members
Points: 648 Visits: 279
Comments posted to this topic are about the item Order My Data
Igor Micev
Igor Micev
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4622 Visits: 4948
All options are true except this one
"CREATE CLUSTERED INDEX IDX_A ON #temp1(i,a)"
You should correct your question.


Igor Micev,
SQL Server developer at Seavus
www.seavus.com
steve.jacobs
steve.jacobs
SSChasing Mays
SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)SSChasing Mays (648 reputation)

Group: General Forum Members
Points: 648 Visits: 279
IgorMi (12/1/2013)
All options are true except this one
"CREATE CLUSTERED INDEX IDX_A ON #temp1(i,a)"
You should correct your question.


Igor, you are correct and thank you for pointing it out. If you were to combine the index with the Order By, then column a would be sorted and the only option that would not "work" would be the one you noted. I would like to correct the question in stating "if you had the option to add only one and not multiples..." such as index and ORDER BY. The intent of the question is adding only one value from the list to order column 'a' not multiples. For example:



create table #temp1
(
i int identity(1,1),
a numeric(8,2) default '0'
)

CREATE CLUSTERED INDEX IDX_A ON #temp1(a)


insert into #temp1 (a)
select 1
union all
select '32'
union all
select 21
union all
select null
union all
select '0'
union all
select .5
union all
select NULL
union all
select '.5'
union all
select '32'


select i, cast((cast(#temp1.a as float) + 10) as varchar) from #temp1
drop table #temp1





Administers, how do I go about "fixing" the question once it is published?

To all that misunderstood the intent and the inadequate question, my apologiesErmm
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3871 Visits: 3276
steve.jacobs (11/30/2013)
Comments posted to this topic are about the item <A HREF="/questions/T-SQL/104494/">Order My Data</A>

OhiOhiOhi.
The only right answer is add a "order by clause" to the select statement.
Without the order by you are not granted about the order of the data.
It depends on cpu load, memory, concurrency, parallel processing.
You can run your test and have the same result, but in the production environment you may have unexpected order.

I run on tuttopodismo
karyn.webb
karyn.webb
Mr or Mrs. 500
Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)

Group: General Forum Members
Points: 556 Visits: 861
That was my understanding as well. I only selected the one answer. And I did read that I should select 4. But I'm pretty sure that Hugo has had strong words in the past about not relying on the indexes to order data.

And now I'm thinking that I made that all up.
Mr. Kapsicum
Mr. Kapsicum
SSC Eights!
SSC Eights! (832 reputation)SSC Eights! (832 reputation)SSC Eights! (832 reputation)SSC Eights! (832 reputation)SSC Eights! (832 reputation)SSC Eights! (832 reputation)SSC Eights! (832 reputation)SSC Eights! (832 reputation)

Group: General Forum Members
Points: 832 Visits: 980
Carlo Romagnano (12/1/2013)
steve.jacobs (11/30/2013)
Comments posted to this topic are about the item <A HREF="/questions/T-SQL/104494/">Order My Data</A>

OhiOhiOhi.
The only right answer is add a "order by clause" to the select statement.
Without the order by you are not granted about the order of the data.
It depends on cpu load, memory, concurrency, parallel processing.
You can run your test and have the same result, but in the production environment you may have unexpected order.




+1.

The Only way you can guarantee ORDERED result set, is by adding ORDER BY in the Statement.
(Even Though This Question has Very Less Data, it will order the result by INDEXING, But in PRACTICAL SCENARIOS it will not work) ;-)
Evgeny
 Evgeny
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1328 Visits: 743
What is wrong with this answer?

CREATE NONCLUSTERED INDEX IDX_A ON #temp1(a)

Even though I agree that only order by guarantee the order...
palotaiarpad
palotaiarpad
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1984 Visits: 763
If i need a specific order i'll use ORDER BY. It's the clearest method to avoid future problems. Cool
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19675 Visits: 13250
Evgeny (12/1/2013)
What is wrong with this answer?

CREATE NONCLUSTERED INDEX IDX_A ON #temp1(a)



+1

Why is this answer "incorrect"?

Flawed question today, better luck next time :-)


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3871 Visits: 3276
Koen Verbeeck (12/2/2013)
Evgeny (12/1/2013)
What is wrong with this answer?

CREATE NONCLUSTERED INDEX IDX_A ON #temp1(a)



+1

Why is this answer "incorrect"?

Flawed question today, better luck next time :-)

It's wrong because the optimizer never use NONCLUSTERED index, if it do not need it.

I run on tuttopodismo
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search