Last active
June 17, 2022 22:38
-
-
Save costr/2ffec913dea3d92f5b57d498db94f69e to your computer and use it in GitHub Desktop.
Creating Unique Token At Table Level
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
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