... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2012-03-06

Singleton Tables in SQL Server

In SQL Server, you can create a "singleton" table (a table with one row) like this:

CREATE TABLE configurationData
( id AS 1 PRIMARY KEY
, properties NVARCHAR(MAX) NOT NULL
)

The primary key is a computed column with a constant value. Consequently, any attempt to insert a second row into the table will be greeted with a constraint violation error.

Note that this method only ensures that there cannot be two or more rows in the table -- it does not prevent the table from being empty.

Blog Archive