Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:44:29+00:00 2026-06-16T04:44:29+00:00

I am trying to use the SQL Server Database Project to keep all our

  • 0

I am trying to use the SQL Server Database Project to keep all our table, stored procedure, views etc scripts. I now want a way to be able to keep all our reference (static) data as well. When the tool or project is run it will install all the DB objects and the insert all the reference data.

I found similar articles for vs 2010 but they were using things like Team Edition for Database professionals.

  • Get our DB under source control.
  • Synchronize our local development DB with latest version in source control.
  • Work with Visual Studio 2012 and SQL Server 2012
  • Use .Net tools as far as possible and not something like Redgate (Redgate is great but I don’t want to for out for it just yet if I can use tools in VS 2012)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:44:31+00:00Added an answer on June 16, 2026 at 4:44 am

    You can use this approach:

    • Put your reference data into XML files, one per table
    • Add XML files with reference data to your database project
    • Use a Post-Deployment script to extract the data from XML and merge it into your tables

    Here is a more detailed description of each step, illustrated with an example. Let’s say that you need to initialize a table of countries that has this structure:

    create table Country (
        CountryId uniqueidentifier NOT NULL,
        CountryCode varchar(2) NOT NULL,
        CountryName varchar(254) NOT NULL
    )
    

    Create a new folder called ReferenceData under your database project. It should be a sibling folder of the Schema Objects and Scripts.

    Add a new XML file called Country.xml to the ReferenceData folder. Populate the file as follows:

    <countries>
        <country CountryCode="CA" CountryName="Canada"/>
        <country CountryCode="MX" CountryName="Mexico"/>
        <country CountryCode="US" CountryName="United States of America"/>
    </countries>
    

    Find Script.PostDeployment.sql, and add the following code to it:

    DECLARE @h_Country int
    
    DECLARE @xmlCountry xml = N'
    :r ..\..\ReferenceData\Country.xml
    '
    
    EXEC sp_xml_preparedocument @h_Country OUTPUT, @xmlCountry
    
    MERGE Country AS target USING (
        SELECT c.CountryCode, c.CountryName
        FROM OPENXML(@h_Country, '/countries/country', 1)
        WITH (CountryCode varchar(2), CountryName varchar(254)) as c) AS source (CountryCode, CountryName)
    ON (source.CountryCode = target.CountryCode)
    WHEN MATCHED THEN
        UPDATE SET CountryName = source.CountryName
    WHEN NOT MATCHED BY TARGET THEN
        INSERT (CountryId, CountryCode, CountryName) values (newid(), source.CountryCode, source.CountryName)
    ;
    

    I tried this solution only in VS 2008, but it should be agnostic to your development environment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use SQL Server Management Studio to edit database tables. But I
I'm trying to use a dynamically generated fully-qualified table name in sql server 2008.
I am trying to use Microsoft Sync Framework 2.1 on a SQL Server database.
I am trying to optimize some stored procedures on a SQL Server 2000 database
I'm trying to use SQL Server Profiler (2005) to track down some application performance
I am trying to use a SQL Server 2008 Ranking Function on a query
I'm trying to use LINQ to SQL Server in C#/.NET on Visual Studio 2010.
I'm using SQL Server 2008 (non-R2) and trying to use Report Builder 3.0. When
I am trying to use an update trigger in SQL Server 2000 so that
I am trying to use WCF Services as models for SQL Server Reporting Services

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.