I have SQL Server databases and do changes in them. Some database tables have records that are starting records required my app to run. I would like to do version control ov
For database (schema) versioning we use custom properties, which are added to the database when the installer is ran. The contents of these scripts is generated with our build scripts.
The script to set the properties looks like this:
DECLARE @AssemblyDescription sysname
SET @AssemblyDescription = N'DailyBuild_20090322.1'
DECLARE @AssemblyFileVersion sysname
SET @AssemblyFileVersion = N'0.9.3368.58294'
-- The extended properties DatabaseDescription and DatabaseFileVersion contain the
-- AssemblyDescription and AssemblyFileVersion of the build that was used for the
-- database script that creates the database structure.
--
-- The current value of these properties can be displayed with the following query:
-- SELECT * FROM sys.extended_properties
IF EXISTS (SELECT * FROM sys.extended_properties WHERE class_desc = 'DATABASE' AND name = N'DatabaseDescription')
BEGIN
EXEC sys.sp_updateextendedproperty @name = N'DatabaseDescription', @value = @AssemblyDescription
END
ELSE
BEGIN
EXEC sys.sp_addextendedproperty @name = N'DatabaseDescription', @value = @AssemblyDescription
END
IF EXISTS (SELECT * FROM sys.extended_properties WHERE class_desc = 'DATABASE' AND name = N'DatabaseFileVersion')
BEGIN
EXEC sys.sp_updateextendedproperty @name = N'DatabaseFileVersion', @value = @AssemblyFileVersion
END
ELSE
BEGIN
EXEC sys.sp_addextendedproperty @name = N'DatabaseFileVersion', @value = @AssemblyFileVersion
END
GO