SQL Change Automation 4

Help for older versions available.

Component versioning using a dedicated table and static data with Visual Studio

The following example takes the online approach to handling static data.

  1. Create a SQL Change Automation project

  2. Add a new version table containing static data (see below for example SQL) 

    1. CREATE TABLE [dbo].[component_versions](
    2. [component] [NVARCHAR](64) NOT NULL,
    3. [version] [INT] NOT NULL,
    4. CONSTRAINT [PK_component_versions] PRIMARY KEY CLUSTERED 
    5. (
    6. [component] ASC
    7. ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    8. ) ON [PRIMARY] 
    9. GO
    10. ALTER TABLE [dbo].[component_versions] WITH CHECK ADD CONSTRAINT [CK_component] CHECK  (([component]<>''))
    11. GO
    12. ALTER TABLE [dbo].[component_versions] CHECK CONSTRAINT [CK_component] 
    13. GO
    14. ALTER TABLE [dbo].[component_versions] WITH CHECK ADD CONSTRAINT [CK_version] CHECK  (([version]>(0)))
    15. GO
    16. ALTER TABLE [dbo].[component_versions] CHECK CONSTRAINT [CK_version] 
    17. GO
    18. UPDATE [dbo].[component_versions] SET version = 1 WHERE component = N'customers'
    19. GO
    20. UPDATE [dbo].[component_versions] SET version = 1 WHERE component = N'regions'
    21. GO
  3. Refresh  SQL Change Automation, select the table, and click Import and generate script



  4. Click Refresh and then right-click on an object and click Include Table Data to include static data for the table 



  5. Click Refresh again, and then Import and generate script to create a migration script containing the static data. It might look like this:

Now everything is set. 

When the corresponding database objects next need to change, a new component version will be needed.

Update the record in the database and import a new migration script. It will contain the following logic or equivalent: 

  1. UPDATE component_versions SET version = 3 WHERE component = M'customers'

Didn't find what you were looking for?