Created
October 21, 2022 16:50
-
-
Save BrentOzar/d99517f1a24abb68c0f22f4c3c61be51 to your computer and use it in GitHub Desktop.
Stack Overflow Data Dump Schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [StackOverflow] | |
GO | |
/****** Object: Table [dbo].[Badges] Script Date: 10/21/2022 12:48:56 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Badges]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[Badges]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[Name] [nvarchar](40) NOT NULL, | |
[UserId] [int] NOT NULL, | |
[Date] [datetime] NOT NULL, | |
CONSTRAINT [PK_Badges__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[Comments] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Comments]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[Comments]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[CreationDate] [datetime] NOT NULL, | |
[PostId] [int] NOT NULL, | |
[Score] [int] NULL, | |
[Text] [nvarchar](700) NOT NULL, | |
[UserId] [int] NULL, | |
CONSTRAINT [PK_Comments__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[LinkTypes] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LinkTypes]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[LinkTypes]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[Type] [varchar](50) NOT NULL, | |
CONSTRAINT [PK_LinkTypes__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[PostHistory] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PostHistory]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[PostHistory]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[PostHistoryTypeId] [int] NOT NULL, | |
[PostId] [int] NOT NULL, | |
[RevisionGUID] [uniqueidentifier] NOT NULL, | |
[CreationDate] [datetime] NOT NULL, | |
[UserId] [int] NULL, | |
[UserDisplayName] [nvarchar](40) NULL, | |
[Comment] [nvarchar](max) NULL, | |
[Text] [nvarchar](max) NULL, | |
CONSTRAINT [PK_PostHistory__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[PostHistoryTypes] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PostHistoryTypes]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[PostHistoryTypes]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[Type] [nvarchar](50) NOT NULL, | |
CONSTRAINT [PK_PostHistoryTypes__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[PostLinks] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PostLinks]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[PostLinks]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[CreationDate] [datetime] NOT NULL, | |
[PostId] [int] NOT NULL, | |
[RelatedPostId] [int] NOT NULL, | |
[LinkTypeId] [int] NOT NULL, | |
CONSTRAINT [PK_PostLinks__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[Posts] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Posts]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[Posts]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[AcceptedAnswerId] [int] NULL, | |
[AnswerCount] [int] NULL, | |
[Body] [nvarchar](max) NOT 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, | |
[ParentId] [int] NULL, | |
[PostTypeId] [int] NOT NULL, | |
[Score] [int] NOT NULL, | |
[Tags] [nvarchar](150) NULL, | |
[Title] [nvarchar](250) NULL, | |
[ViewCount] [int] NOT NULL, | |
CONSTRAINT [PK_Posts__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[PostTypes] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PostTypes]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[PostTypes]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[Type] [nvarchar](50) NOT NULL, | |
CONSTRAINT [PK_PostTypes__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[Tags] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Tags]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[Tags]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[TagName] [nvarchar](150) NOT NULL, | |
[Count] [int] NOT NULL, | |
[ExcerptPostId] [int] NOT NULL, | |
[WikiPostId] [int] NOT NULL, | |
CONSTRAINT [PK_Tags__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[Users] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[Users]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[AboutMe] [nvarchar](max) NULL, | |
[Age] [int] NULL, | |
[CreationDate] [datetime] NOT NULL, | |
[DisplayName] [nvarchar](40) NOT NULL, | |
[DownVotes] [int] NOT NULL, | |
[EmailHash] [nvarchar](40) NULL, | |
[LastAccessDate] [datetime] NOT NULL, | |
[Location] [nvarchar](100) NULL, | |
[Reputation] [int] NOT NULL, | |
[UpVotes] [int] NOT NULL, | |
[Views] [int] NOT NULL, | |
[WebsiteUrl] [nvarchar](200) NULL, | |
[AccountId] [int] NULL, | |
CONSTRAINT [PK_Users_Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[Votes] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Votes]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[Votes]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[PostId] [int] NOT NULL, | |
[UserId] [int] NULL, | |
[BountyAmount] [int] NULL, | |
[VoteTypeId] [int] NOT NULL, | |
[CreationDate] [datetime] NOT NULL, | |
CONSTRAINT [PK_Votes__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Table [dbo].[VoteTypes] Script Date: 10/21/2022 12:48:57 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[VoteTypes]') AND type in (N'U')) | |
BEGIN | |
CREATE TABLE [dbo].[VoteTypes]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[Name] [varchar](50) NOT NULL, | |
CONSTRAINT [PK_VoteType__Id] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
) ON [PRIMARY] | |
END | |
GO | |
/****** Object: Index [Reputation] Script Date: 10/21/2022 12:48:57 PM ******/ | |
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND name = N'Reputation') | |
CREATE NONCLUSTERED INDEX [Reputation] ON [dbo].[Users] | |
( | |
[Reputation] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment