Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SQL等价于;使用;对于模式?_Sql Server_Schema - Fatal编程技术网

Sql server SQL等价于;使用;对于模式?

Sql server SQL等价于;使用;对于模式?,sql-server,schema,Sql Server,Schema,我正在使用一个SQL Server DB,它的表分布在多个模式中(这不是我的想法),因此查询结果如下所示: select col1, col2 from some_ridiculously_long_schema_name.table1 t1 inner join another_really_long_schema_location.table2 t2 on... using some_ridiculously_long_schema_name, another_really

我正在使用一个SQL Server DB,它的表分布在多个模式中(这不是我的想法),因此查询结果如下所示:

select col1, col2
from some_ridiculously_long_schema_name.table1 t1
inner join
    another_really_long_schema_location.table2 t2
    on...
using some_ridiculously_long_schema_name, another_really_long_schema_location
。。。你明白了

当我将查询放入存储过程等时,这是一个小小的不便,但当我执行临时查询时,这会是一个真正的痛苦

是否有某种方法可以“包含”我感兴趣的所有模式,并使它们自动可寻址?(LINQPad会这样做)

我希望能够指出这样的东西:

select col1, col2
from some_ridiculously_long_schema_name.table1 t1
inner join
    another_really_long_schema_location.table2 t2
    on...
using some_ridiculously_long_schema_name, another_really_long_schema_location
。。。然后查询,这些模式包含在我的地址空间中


如果没有类似的东西存在,我将研究同义词,但我更愿意这样做,而不必将工件添加到数据库中。

不,没有。synonims是唯一的方法。

这将不起作用,因为如果两种模式中都有Table1,那么您如何知道您想要什么模式?

Red Gate销售一种SQL工具,可将intellisense添加到server management studio。从未尝试过,但它可能有助于减少击键次数:

我知道您的感受,如果您需要保留模式(例如,如果每个模式中的表名相同),并且您一直在编写跨模式连接的查询,那么我能提供的最佳建议是缩短您的模式名

技术含量低,我肯定不是你想听的


上面建议的同义词只在对象级别工作(据我所知,你不能有整个模式的同义词),因此你必须为你想从默认模式之外使用的每个表、视图、存储过程、函数等都有一个同义词。

我希望这和名称空间一样工作——如果没有冲突,它可以工作,如果有,我会得到一个错误,指出我需要完全限定模式名。