Skip to content

Instantly share code, notes, and snippets.

@costr
Last active June 17, 2022 22:38
Show Gist options
  • Save costr/2ffec913dea3d92f5b57d498db94f69e to your computer and use it in GitHub Desktop.
Save costr/2ffec913dea3d92f5b57d498db94f69e to your computer and use it in GitHub Desktop.
Creating Unique Token At Table Level
CREATE TABLE [dbo].[tokens]
(
[id] INT IDENTITY(1,1) NOT NULL,
[token] NCHAR(6) NOT NULL CONSTRAINT DF_subscribertokens_token DEFAULT CONVERT(nvarchar(6),LEFT(REPLACE(NEWID(),'-',''),6)),
[created] DATETIME NOT NULL CONSTRAINT DF_subscribertokens_created DEFAULT getutcdate(),
[notes] VARCHAR(MAX) NULL,
[deactivated] BIT NOT NULL CONSTRAINT DF_subscribertokens_deactivated DEFAULT 0,
CONSTRAINT [PK_tokens] PRIMARY KEY CLUSTERED ([id] ASC),
CONSTRAINT UC_tokens_token UNIQUE (token)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment