Search code examples
sql-serversql-server-data-toolsdatabase-project

Composite Projects - handling additional columns


From this post....

http://blogs.msdn.com/b/ssdt/archive/2012/06/26/composite-projects-and-schema-compare.aspx

...it seems that (Same) Database References are a way to share common parts of a database.

If a specific database needs additional columns on a table from a (Same) Database Reference is there any way of handling that?

I was hoping you might be able to override the definition of a table from a Database Reference simply by re-declaring the table in the referencing Database Project.

e.g. if you had a Employee table in a Common Database project, a definition for Employee table in a Client Database referencing Common Database would override the definition in the Common project. Instead when you go to deploy the porject you get the error...

SQL71508: The model already has an element that has the same name dbo.Employee.

EDIT:
Anticipating the feedback below, the resolution I've made is to not use database references for the existing client databases. Instead I've created a structure as follows....

+OurCompanyDatabases
    +Common
        Common.sqlproj
        +dbo...
    +ClientA
        +dbo....
    +ClientB
        +dbo....
ClientA.sqlproj
ClientB.sqlproj

So I've got multiple sqlproj files within the same folder and I include and exclude files from the projects as required.

So for example ClientA's Sales table has a ClientARewardsID column added I exclude the Sales table within the /OurCompanyDatabases/Common/dbo folder and create add a new Sales table within the /OurCompanyDatabases/ClientA/dbo folder.

This way Client A and Client B can retain the full use of SSDT update and deployment, whilst minimizing the duplication of sql scripts. I'm hoping this will reduce the cost of maintenance on the sites.

Going forward I will use database references and additional columns will be added in new tables with a foreign 1:1 foreign key relationship with the Common table.


Solution

  • No it doesn't support an inheritance type model and you can only really share complete objects so in your case you would have it structured like:

    • proj a - TableA
      • references - proj shared
    • proj b - TableA
      • references - proj shared
    • proj shared - TableXYZ

    Then you can have two different definitions of TableA but still share all of the objects that are the same.

    There is another option you could not include the table definition in SSDT or include one or the other and then handle any changes and the deployment yourself in post deploy scripts and use my filter (http://agilesqlclub.codeplex.com/) to stop ssdt deploying any changes to your table but this sort of invalidates one of the main reasons for using ssdt (merge type deployments for free).

    ed