简体   繁体   中英

Cross-database tables?

I have a relatively large database application that has a user table with a record for every member of staff.

I have another, tiny, database that is a record of all educational courses attended by a member of staff. This database is actually only a handful of tables migrated from a legacy app and is now standalone.

The two applications share nothing in common other than the users.

Is it "best" to simply import the smaller database tables in to the larger database and update the application or is it possible to access/use in a relation the user table in the larger database?

Thanks

Assuming the small database will never write to the large one, I would set up a view on the small DB that provides the exact info you need. If both db's are hosted on the same server, the view can select from the large db by specifying the full name of the table (server.database.schema.table), assuming the user has the appropriate access rights. If they are on separate database servers, you will also need to setup a linked database.

You can access tables in another database (in the same server) using a fully qualified name:

<database name>.<schema>.<table name>

You need to ensure that the login used has the right permissions though.

With linked servers you can also access databases on different servers.

You do have to keep in mind that this will couple one of the databases to the other - whether that is OK or not depends on the databases, the applications and how they are used.

Sharing a database among several applications is not uncommon. Assuming there are no name collisions and only 20 small tables I would recommend importing the smaller db's tables into the larger.

Instead of worrying about the administration and troubleshooting of a dependent database (or linked server) and all the security and maintenance issues (and integrity!) that could arise, you could have a single db and mitigate most of those potential issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM