Skip to content

Instantly share code, notes, and snippets.

@markmo
Created March 19, 2013 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmo/5193225 to your computer and use it in GitHub Desktop.
Save markmo/5193225 to your computer and use it in GitHub Desktop.
Create Tally Table - useful for removing and creating duplicates
--===== Create and populate the Tally table on the fly
SELECT TOP 11000 --equates to more than 30 years of dates
IDENTITY(INT,1,1) AS N
INTO dbo.Tally
FROM Master.dbo.SysColumns sc1,
Master.dbo.SysColumns sc2
--===== Add a Primary Key to maximize performance
ALTER TABLE dbo.Tally
ADD CONSTRAINT PK_Tally_N
PRIMARY KEY CLUSTERED (N) WITH FILLFACTOR = 100
--===== Allow the general public to use it
GRANT SELECT ON dbo.Tally TO PUBLIC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment