問題描述
我最初的問題是關于是將 ASPNETDB.MDF 與應用程序數據庫分開還是將所有表合并到一個數據庫中.查看之前的問題/答案,我了解到這取決于會員數據是否會在多個應用程序之間共享.
My original question was about whether to keep separate ASPNETDB.MDF from the application database or merge all the tables in one database. Checking the previous questions/answers, I learned that it depends on whether the membership data would be shared across several applications.
現在,我的問題是這個.如果我決定將 ASPNETDB.MDF 與應用程序數據庫分開,如何查詢位于 2 個不同數據庫中的 2 個表?
Now, my question is this. In case I decide to keep ASPNETDB.MDF separate from the application DB, how can I query 2 tables located in 2 different databases?
感謝您的幫助.
推薦答案
如果您在同一數據庫服務器上有兩個數據庫/模式,您可以使用以下語法跨數據庫查詢:
If you have two databases/schemas on the same database server, you can query across databases with the following syntax:
select *
from database1.dbo.table1 t1 join database2.dbo.table2 t2 on
t1.field1 = t2.field2
如果它們在物理上獨立的服務器上,您仍然可以進行跨庫查詢,但您需要先鏈接服務器:
If they are on physically separate servers, you can still do a cross-database query, but you need to link the servers first:
http://msdn.microsoft.com/en-us/library/aa213778(v=sql.80).aspx
這篇關于如何查詢位于不同數據庫中的表?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!