Skip to content

Instantly share code, notes, and snippets.

@gavincampbell
Last active December 17, 2015 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavincampbell/679b9486095e3e43639d to your computer and use it in GitHub Desktop.
Save gavincampbell/679b9486095e3e43639d to your computer and use it in GitHub Desktop.
Pattern for creating tables that can only ever have one row.
CREATE TABLE ConfigTable(
[ConstrainToSingleRow] [BIT] NOT NULL DEFAULT ((1)),
SomeValue [INT] NULL,
A_String [VARCHAR](10) NULL,
Flag1 [BIT] NULL DEFAULT ((0)),
Flag2 [BIT] NULL DEFAULT ((0)),
A_decimal [DECIMAL](9, 2) NULL,
PRIMARY KEY CLUSTERED
(
[ConstrainToSingleRow] ASC
)
) ON [PRIMARY]
ALTER TABLE ConfigTable WITH CHECK ADD CHECK (([ConstrainToSingleRow]=(1)))
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment