The Same Database
reference allows you to split a single database into multiple projects. This is useful for cases where a project is very large or where different teams manage different parts of the database.
If you consider that you have two .sqlproj SSDT database projects with the following structure:
Project1 - table_a Project2 - proc_a
proc_a reads from table_a using the code:
select column from table_a
If table_a is not in the same project, SSDT can not validate that column
exists on the table. In this case a same database
reference can be added to Project2
that references the dacpac that is created by Project1
To add a Same Database
reference you right click on the References
folder in Solution Explorer and choose to add a Database Reference
, you are then presented with the following dialog:
Choose the source of the reference, i.e. another project in the same solution or a dacpac. Note a system database cannot be added as a Same Database
reference but because of how SQL Server resolves objects you can still call those using the two part, schema and table name.
Once you have added the reference you can call objects in the referenced project using the standard 1 or 2 part name such as:
select column from table_a
or
select column from schema.table_a