New answers tagged row
You could define the ID as a computed column evaluating to a constant value, and declare that column to be unique: CREATE TABLE dbo.Configuration ( ID AS CAST(1 AS tinyint), -- or: AS bit ... -- other columns CONSTRAINT UQ_Configuration_ID UNIQUE (ID) );
You can also use trigger.. create trigger LimitTable on YourTableToLimit after insert as declare @tableCount int select @tableCount = Count(*) from YourTableToLimit if @tableCount > 50 begin rollback end go
These two constraints would do: CREATE TABLE dbo.Configuration ( ConfigurationID TINYINT NOT NULL DEFAULT 1, -- the rest of the columns CONSTRAINT Configuration_PK PRIMARY KEY (ConfigurationID), CONSTRAINT Configuration_OnlyOneRow CHECK (ConfigurationID = 1) ) ; You need both the PRIMARY KEY (or a UNIQUE constraint) so no two rows have the ...
Seems a bit of an odd requirement but ho-hum :) You could just have a constraint on the table and then only allow updates (no insert or deletes) to the table? CREATE TABLE dbo.Config ( ID INT identity(1,1), CONFIGURATION VARCHAR(MAX), constraint ck_limitrows CHECK (ID <=1) ); It's a bit of a hackey way to do it though, would it not ...
Top 50 recent answers are included