views:

110

answers:

4

We are using SQL Server 2005 at work and when development started it was decided that multiple databases would be created. For example, we have one database for Individual say dbIndividual and another one for Translation say dbLocale.

So far this has simplified the backing up and potential restore greatly as we just need to backup what we need (unless there's a way to backup/restore a schema only that we don't know of.)

This cause us to have multiple queries with JOINS over multiple database table and files.

for example:

select customer.firstname, address.addressL1, addressType.value
from dbIndividual.dbo.customer
inner join dbIndividual.dbo.address
    on fkCustomerID = iCustomerID
inner join dbLocale.translation.addressType
    on fkAddressTypeID = iAddressTypeID
    and fkLangID = 1

Is there any drawback to this? Beside the obvious that we can't enforce data integrity across multiple db. Will it slow things down when joining since the data is potentially on totally different part of the disk?

Reason I am asking is because we are in the middle of reorganizing our infrastructure and this is one potential issue that kept popping up.

+4  A: 

Current best practice is to use the same database with multiple schemas. Each schema can be put on its own file, which can then be backed up easily. It also allows you to enforce foreign key constraints.

We used to use the multiple database model like your company, and we recently switched all new development to just use schemas. We have not lost anything by doing so and have gained the ability to enforce our foreign keys, which is huge.

Keith Rousseau
+3  A: 

why didn't you use SCHEMAs and FILEGROUPS to do this instead? This way you still have separation and you can restore and backup just filegroups if you don't want to do complete backups. And you would have no problem with referential integrity either since you can have foreign keys

SQLMenace
I actually was only aware of schema prior to posting this and thought it was a pita that you couldn't just back them up as you would with other products. Vaguely knew what Filegroups were but now that I read your post and tested one it would do exactly what we want.I guess that we are having performance drawback from joining so many different database that can reside in totally different part of the disk in unorganized sections.
jfrobishow
+5  A: 

Foreign keys are one of the main reason to use a relational database. if you can't use them when they are needed, because data is in different databases, then splitting your tables across multiple databases is bad.

KM
Couldn't agree more!
PostMan
A: 

I will point out that you can enforce referential integrity across databases by using triggers and should be doing so in your current design.That said, I like the same database with multiple schema model that Keith Rousseau and SQLMenace suggested.

HLGEM