How do I query tables located in another database?

My initial question was whether to save a separate ASPNETDB.MDF from the application database or to combine all the tables in one database. Checking the previous questions / answers, I found out that it depends on whether membership data will be distributed between several applications.

Now, my question is this. In case I decided to leave ASPNETDB.MDF separate from the application database , how can I query 2 tables located in 2 different databases?

Thanks for the help.

+6
source share
1 answer

If you have two databases / schemas on the same database server, you can query the following syntax through databases:

select * from database1.dbo.table1 t1 join database2.dbo.table2 t2 on t1.field1 = t2.field2 

If they are located on physically separate servers, you can still perform a cross-database query, but first you need to bind the servers:

http://msdn.microsoft.com/en-us/library/aa213778(v=sql.80).aspx

+13
source

Source: https://habr.com/ru/post/886587/


All Articles