|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, December 11, 2012 8:53 AM
Points: 107,
Visits: 205
|
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Sunday, May 12, 2013 3:47 PM
Points: 76,
Visits: 457
|
|
Perhaps is more easily as follows
INSERT dbo.TinyTally default values GO 254 instead of
INSERT dbo.TinyTally(N) VALUES(IDENT_CURRENT('dbo.TinyTally')); GO INSERT dbo.TinyTally(N) VALUES(IDENT_CURRENT('dbo.TinyTally')+1); GO 254 -- Really cool tidbit I picked up from SQL Saturday #40 (will now repeat batch 254 times!) SET IDENTITY_INSERT dbo.TinyTally OFF; GO
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, December 11, 2012 8:53 AM
Points: 107,
Visits: 205
|
|
Sweet!
Keith Wiggans
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 12:36 PM
Points: 2,549,
Visits: 18,880
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, December 11, 2012 8:53 AM
Points: 107,
Visits: 205
|
|
Yup, I actually tried out the default values script and it works awesome. No settings, just sraight insert statements. Thanks for the input. Hopefully someone else gained additional understanding as well. Later,
Keith Wiggans
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 12:36 PM
Points: 2,549,
Visits: 18,880
|
|
Not exactly what I meant, although that is handy.
The fact that your column is an identity column is also what does the trick. The default_values won't help you if that's not the case, especially if the column doesn't have a default specified.
Since your column IS an identity column, you were having to say SET IDENTITY_INSERT ON before your script, and SET IDENTITY_INSERT OFF after you were done. This basically disables the automatic incrementation of the column value (if you didn't specify the IDENTITY_INSERT setting, it would have thrown an error), but in your case, this is what you want.
Therefore, skipping the SET IDENTITY_INSERT ON and just inserting 254 times gave you the values in that column without having to do the extra work.
Hope that helps explain a little better.
Jon
--------------------------------------------------------- How best to post your question How to post performance problems Tally Table:What it is and how it replaces a loop
"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
|
|
|
|