本文介绍了PHP SQL Server 数据库选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个 SQL Server 实例上有三个 SQL Server 数据库.每次查询不同的数据库,都要选择数据库.
I have three SQL Server databases on one SQL Server instance. Every time I do query to different databases, I have to select the database.
有没有办法在没有数据库选择的情况下进行查询.像这样:
Is there a way to do query without database select. Like this:
SELECT * FROM database_name.table_name WHERE id = 1
推荐答案
是的,您可以 使用标识符作为对象名称.这应该有效:
Yes, you can use identifiers as object names. This should work:
SELECT *
FROM database_name..table_name
WHERE id = 1
它是 database_name.schema_name.object_name
的变体.链接中有更多示例.
It's a variation of database_name.schema_name.object_name
. There are more examples in the link.
您使用的用户需要有权访问所涉及的数据库和表.
The user you use needs to have access to both the database(s) and table(s) involved.
这篇关于PHP SQL Server 数据库选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!