We have a database (SQL Server 2005) which we would like to get under source control. As part of that we are going to have a version table to store the current version number of the database. Is there a way to limit that table to only holding one row? Or is storing the version number in a table a bad idea?
Ended up using this approach:
CREATE TABLE [dbo].[DatabaseVersion] ( [MajorVersionNumber] [int] NOT NULL, [MinorVersionNumber] [int] NOT NULL, [RevisionNumber] [int] NOT NULL ) GO Insert DataBaseVersion (MajorVersionNumber, MinorVersionNumber, RevisionNumber) values (0, 0, 0) GO CREATE TRIGGER DataBaseVersion_Prevent_Delete ON DataBaseVersion INSTEAD OF DELETE AS BEGIN RAISERROR ('DatabaseVersion must always have one Row. (source = INSTEAD OF DELETE)', 16, 1) END GO CREATE TRIGGER DataBaseVersion_Prevent_Insert ON DataBaseVersion INSTEAD OF INSERT AS BEGIN RAISERROR ('DatabaseVersion must always have one Row. (source = INSTEAD OF INSERT)', 16, 1) END GO
Use a trigger.