Skip to content

Instantly share code, notes, and snippets.

@cbcwebdev
Created May 3, 2012 22:05
Show Gist options
  • Save cbcwebdev/2589867 to your computer and use it in GitHub Desktop.
Save cbcwebdev/2589867 to your computer and use it in GitHub Desktop.
Modern Directory Table Structure
CREATE TABLE [dbo].[Directories]
(
[AggregateId] UNIQUEIDENTIFIER NOT NULL,
[Name] NVARCHAR(64) NOT NULL,
[Route] NVARCHAR(128) NOT NULL UNIQUE,
[Route_Hash] AS CAST(HASHBYTES('SHA1', [Route]) AS VARBINARY(20)) PERSISTED UNIQUE,
[Depth] TINYINT NOT NULL,
[ParentId] UNIQUEIDENTIFIER NULL,
CONSTRAINT [PK_Directories] PRIMARY KEY NONCLUSTERED (
[AggregateId] ASC
)
)
GO
CREATE CLUSTERED INDEX [CX_Directories_AggregateId_ParentId_Depth]
ON [dbo].[Directories] (AggregateId ASC, ParentId ASC, Depth ASC);
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment