如何在数据库外部访问模式及其对象

时间:2018-01-24 09:49:41

标签: sql sql-server

我在Azure中有2个数据库,

DB1, DB2

我在DB1中创建了作为DB1的模式,并在模式下创建了一些表,如

DB1.table1 DB1.table2

我的疑问是,我们可以借助DB2访问该表 [DB1] .DB1.table1 rite?

但我可以访问[schema]。[table]。在我的示例中DB1.table1。

有没有选择。

2 个答案:

答案 0 :(得分:1)

您可以使用以下方法查询另一个数据库中的表:

SELECT tbl.*
FROM [DatabaseName].[Schema].[TableName] as tbl

示例:

SELECT * FROM northwind.dbo.orders where id = @id

答案 1 :(得分:0)

您可以像以下一样创建#include <iostream> #include <vector> #include <string> #include <memory> class FilterData { using fvec = std::vector<float>; public: FilterData(const std::string& filename) { // (simulate read from file...) m_filterACoeffs = std::make_unique<fvec>(); m_filterBCoeffs = std::make_unique<fvec>(); m_filterACoeffs->emplace_back(1.f); m_filterACoeffs->emplace_back(2.f); m_filterACoeffs->emplace_back(3.f); m_filterBCoeffs->emplace_back(-1.f); m_filterBCoeffs->emplace_back(-2.f); m_filterBCoeffs->emplace_back(-3.f); } const fvec* getFilterACoeffs() { return m_filterACoeffs.get(); } const fvec* getFilterBCoeffs() { return m_filterBCoeffs.get(); } private: std::unique_ptr<fvec> m_filterACoeffs; std::unique_ptr<fvec> m_filterBCoeffs; }; int main() { FilterData filterData("thefile.bin"); auto p_filterACoeffs = filterData.getFilterACoeffs(); auto p_filterBCoeffs = filterData.getFilterBCoeffs(); std::cout << "Filter A is: " << p_filterACoeffs->at(0) << " , " << p_filterACoeffs->at(1) << " , " << p_filterACoeffs->at(2) << std::endl; std::cout << "Filter B is: " << p_filterBCoeffs->at(0) << " , " << p_filterBCoeffs->at(1) << " , " << p_filterBCoeffs->at(2) << std::endl; }

Synonym

然后,您可以从第二个数据库运行select语句,如:

Use DB2
Create synonym Syn_SomeName
for  [DB1].DB1.table1

可以找到here的同义词的更多信息,但是据说你不想为每个表创建一个同义词,只为人们可能需要查询的表格。