|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Today @ 2:11 PM
Points: 210,
Visits: 234
|
|
| Comments posted to this topic are about the item Sequence
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, June 07, 2013 2:42 PM
Points: 1,662,
Visits: 1,710
|
|
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
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 7:11 AM
Points: 877,
Visits: 1,159
|
|
Good question. Thanks 'Oleg Netchaev' for query & link.
Thanks
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 6:47 AM
Points: 847,
Visits: 770
|
|
Nice question, thanks also Oleg for the remark and link to Triangular Joins.
Regards, Iulian
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 9,410,
Visits: 6,495
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:27 AM
Points: 1,384,
Visits: 4,881
|
|
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?
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, March 25, 2013 4:03 AM
Points: 850,
Visits: 71
|
|
Good question.
Regards, Jagan.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 9,410,
Visits: 6,495
|
|
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?
Member of LinkedIn. My blog at LessThanDot.
 MCSA SQL Server 2012 - MCSE Business Intelligence
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Tuesday, May 28, 2013 9:52 AM
Points: 814,
Visits: 1,137
|
|
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
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 9,410,
Visits: 6,495
|
|
|
|
|