USE [EnVisage]
GO

begin tran
	
	IF NOT EXISTS(SELECT * FROM sys.columns 
				WHERE Name = N'Version' AND Object_ID = Object_ID(N'History'))
	BEGIN
		ALTER TABLE History ADD [Version] smallint NULL default(2)
	END
	GO

	UPDATE History SET [Version] = 1 WHERE [Version] IS NULL
	GO

	ALTER TABLE History ALTER COLUMN [Version] smallint NOT NULL
	GO

	if exists (select 1 from sys.default_constraints WHERE Name = N'DF_History_TimeStamp' AND parent_object_id = Object_ID(N'History'))
	begin
		ALTER TABLE History DROP CONSTRAINT [DF_History_TimeStamp]
	end
	GO

	ALTER TABLE History ALTER COLUMN [Timestamp] datetime NOT NULL
	GO

commit tran