Why is using OPENQUERY on a local server bad?

后端 未结 3 1067
不知归路
不知归路 2021-02-09 19:18

I\'m writing a script that is supposed to run around a bunch of servers and select a bunch of data out of them, including the local server. The SQL needed to SELECT the data I n

3条回答
  •  一向
    一向 (楼主)
    2021-02-09 19:53

    In addition to what @OMG Ponies said, it's simply unnecessary. There's no reason to introduce ad-hoc query and distributed transaction semantics when you don't have to. When you use OPENQUERY you take on all of the negative aspects of dynamic SQL, including less predictable plans and the server's inability to accurately track dependencies.

    OPENQUERY also requires the local user to have permissions to the target server, which is probably not what you want unless it's an administrative script. You can't expect every user of one database to have the same permissions to every other database.

提交回复
热议问题