Skip to content

Instantly share code, notes, and snippets.

@erikdarlingdata
Created November 24, 2020 21:41
Embed
What would you like to do?
CREATE TABLE #ts
(
Id int NOT NULL,
--Id int NOT NULL INDEX c CLUSTERED (Id),
--Id int NOT NULL PRIMARY KEY,
--Id int IDENTITY, /*If you use this one, also comment out the Id column in the select*/
AcceptedAnswerId int NULL,
AnswerCount int NULL,
ClosedDate datetime NULL,
CommentCount int NULL,
CommunityOwnedDate datetime NULL,
CreationDate datetime NOT NULL,
FavoriteCount int NULL,
LastActivityDate datetime NOT NULL,
LastEditDate datetime NULL,
LastEditorDisplayName nvarchar(40) NULL,
LastEditorUserId int NULL,
OwnerUserId int NULL,
Score int NOT NULL,
Tags nvarchar(150) NULL,
Title nvarchar(250) NULL,
ViewCount int NOT NULL
);
INSERT #ts
SELECT
p.Id,
p.AcceptedAnswerId,
p.AnswerCount,
p.ClosedDate,
p.CommentCount,
p.CommunityOwnedDate,
p.CreationDate,
p.FavoriteCount,
p.LastActivityDate,
p.LastEditDate,
p.LastEditorDisplayName,
p.LastEditorUserId,
p.OwnerUserId,
p.Score,
p.Tags,
p.Title,
p.ViewCount
FROM dbo.Posts AS p
WHERE p.Score > 5
AND p.PostTypeId = 1;
DROP TABLE #ts;
GO
CREATE TABLE #tp
(
Id int NOT NULL,
AcceptedAnswerId int NULL,
AnswerCount int NULL,
ClosedDate datetime NULL,
CommentCount int NULL,
CommunityOwnedDate datetime NULL,
CreationDate datetime NOT NULL,
FavoriteCount int NULL,
LastActivityDate datetime NOT NULL,
LastEditDate datetime NULL,
LastEditorDisplayName nvarchar(40) NULL,
LastEditorUserId int NULL,
OwnerUserId int NULL,
Score int NOT NULL,
Tags nvarchar(150) NULL,
Title nvarchar(250) NULL,
ViewCount int NOT NULL
);
INSERT #tp WITH(TABLOCK)
SELECT
p.Id,
p.AcceptedAnswerId,
p.AnswerCount,
p.ClosedDate,
p.CommentCount,
p.CommunityOwnedDate,
p.CreationDate,
p.FavoriteCount,
p.LastActivityDate,
p.LastEditDate,
p.LastEditorDisplayName,
p.LastEditorUserId,
p.OwnerUserId,
p.Score,
p.Tags,
p.Title,
p.ViewCount
FROM dbo.Posts AS p
WHERE p.Score > 5
AND p.PostTypeId = 1
OPTION(MAXDOP 12);
DROP TABLE #tp;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment