SQL Server 查询:主机名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38013577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:41:09  来源:igfitidea点击:

SQL Server Query : Host name

sqlsql-serversql-server-2008

提问by Shahim Khlaifat

I have the exact Query Text and the exact time & date the Query was executed, how can I find the Host Name that executed this query?

我有确切的查询文本以及执行查询的确切时间和日期,如何找到执行此查询的主机名?

I'm using SQL Server 2008.

我正在使用 SQL Server 2008。

采纳答案by Andriy Tolstoy

There is not any table with historical information about the host that executed a query - http://www.sqlservercentral.com/Forums/Topic1334479-146-1.aspx

没有任何包含执行查询的主机的历史信息的表 - http://www.sqlservercentral.com/Forums/Topic1334479-146-1.aspx

回答by Arulkumar

Do you need @@SERVERNAME

你需要 @@SERVERNAME

SELECT @@SERVERNAME

will return the server name where the query was executed.

将返回执行查询的服务器名称。



HOST_NAMEwill return the workstation name

HOST_NAME将返回工作站名称

SELECT HOST_NAME()

回答by Tim Lehner

This is as close as you'll get, I believe:

我相信这是最接近的:

select host_name()

select host_name()

As is mentioned in the docs: "The client application provides the workstation name and can provide inaccurate data. Do not rely upon HOST_NAME as a security feature."

正如文档中所提到的:“客户端应用程序提供了工作站名称并可能提供不准确的数据。不要依赖 HOST_NAME 作为安全功能。”