SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Sequence


Sequence

Author
Message
zulmanclock
zulmanclock
Old Hand
Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)

Group: General Forum Members
Points: 352 Visits: 472
Comments posted to this topic are about the item Sequence
Oleg Netchaev
Oleg Netchaev
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2253 Visits: 1818
This is a good basic question, thank you. One thing I would like to point out is that the update script in question is more complex than it needs to be and it uses what Jeff Moden calls a triangular join, which is one of the most evil things one can do to kill performance of the T-SQL query. Of course back in the dark ages when we had to work with SQL Server 2000, the triangular joins were a necessary evil sometimes, but in nowadays when the end of support for SQL Server 2000 is long as ended and the end of support for SQL Server 2005 is looming (12 of April 2011), it is about time to stop the triangular joins insanity and take a look at the windowing functions instead. For example, the update in question can be easily restated like this:

;with records (RecID, Seq) as
(
select
RecID, row_number() over(partition by Value order by RecID)
from #Test
)
update #Test
set
Seq = records.Seq
from #Test inner join records
on #Test.RecID = records.RecID;



Please, please read Jeff's article: http://www.sqlservercentral.com/articles/T-SQL/61539/
It is a true eye opener!

Just my 2 cents.

Oleg
Hardy21
Hardy21
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2804 Visits: 1399
Good question.
Thanks 'Oleg Netchaev' for query & link.

Thanks
Iulian -207023
Iulian -207023
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2531 Visits: 1248
Nice question, thanks also Oleg for the remark and link to Triangular Joins.

Regards,
Iulian
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: General Forum Members
Points: 65064 Visits: 13298
The question itself was OK, as a test to see what output the T-SQL would give.
But not OK for the purpose mentioned in the explanation, as there are other statements that will do it much better and faster (as Oleg has already mentioned).


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
Toreador
Toreador
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: 3878 Visits: 8129
I get a pile of errors when I run it - Cannot insert the value NULL into column 'Seq'.
I eventually worked out that this is because I have ANSI_NULL_DFLT_ON set to False, so Seq was added as a Not Null column.

This never normally affects me, as I always specify NULL or NOT NULL and don't rely on a default, but can anyone point me in the direction of where this might be set?
jaganmohan.rao
jaganmohan.rao
SSC Eights!
SSC Eights! (868 reputation)SSC Eights! (868 reputation)SSC Eights! (868 reputation)SSC Eights! (868 reputation)SSC Eights! (868 reputation)SSC Eights! (868 reputation)SSC Eights! (868 reputation)SSC Eights! (868 reputation)

Group: General Forum Members
Points: 868 Visits: 71
Good question.

Regards,
Jagan.
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: General Forum Members
Points: 65064 Visits: 13298
Toreador (12/22/2010)
I get a pile of errors when I run it - Cannot insert the value NULL into column 'Seq'.
I eventually worked out that this is because I have ANSI_NULL_DFLT_ON set to False, so Seq was added as a Not Null column.

This never normally affects me, as I always specify NULL or NOT NULL and don't rely on a default, but can anyone point me in the direction of where this might be set?


Right-click on the database in SSMS, select properties and in the properties editor select the options tab. There you can set the value for 'ANSI NULL default'. You can also use the sp_dboption procedure.


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
paul.goldstraw
paul.goldstraw
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1510 Visits: 1765
I got it right based on the fact that an update statement shouldn't ever be able to change the number of records in a table - since 8 rows were inserted the only possible answer was the first one (assuming there was no error). I got it right but was I correct in making that assumption or did I just get lucky? I can't think of any circumstance where an update would do that but have I missed something?

Paul
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: General Forum Members
Points: 65064 Visits: 13298
paul.goldstraw (12/22/2010)
I got it right based on the fact that an update statement shouldn't ever be able to change the number of records in a table - since 8 rows were inserted the only possible answer was the first one (assuming there was no error). I got it right but was I correct in making that assumption or did I just get lucky? I can't think of any circumstance where an update would do that but have I missed something?

Paul


Unless you implement the update as an delete and an insert and something goes horribly wrong in between, I would be very surprised :-)


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
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