Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using GO Repeat To Fill Tally Table Expand / Collapse
Author
Message
Posted Tuesday, August 17, 2010 9:48 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, November 25, 2013 5:33 PM
Points: 107, Visits: 207
Comments posted to this topic are about the item Using GO Repeat To Fill Tally Table

Keith Wiggans
Post #970867
Posted Wednesday, August 18, 2010 12:08 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, July 9, 2014 1:39 AM
Points: 78, Visits: 487
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

Post #970929
Posted Wednesday, August 18, 2010 3:09 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, November 25, 2013 5:33 PM
Points: 107, Visits: 207
Sweet!

Keith Wiggans
Post #970996
Posted Wednesday, August 18, 2010 10:48 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:09 AM
Points: 2,656, Visits: 19,184
Do you understand the difference between the two Keith? Why yours was the harder way?

---------------------------------------------------------
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."
Post #971299
Posted Wednesday, August 18, 2010 11:07 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, November 25, 2013 5:33 PM
Points: 107, Visits: 207
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
Post #971312
Posted Wednesday, August 18, 2010 2:58 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:09 AM
Points: 2,656, Visits: 19,184
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."
Post #971489
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse