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
SQL Server Query : Host name
提问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_NAME
will return the workstation name
HOST_NAME
将返回工作站名称
SELECT HOST_NAME()
回答by Ajay2707
You can check with HostName() as
您可以使用 HostName() 进行检查
SELECT HOST_NAME() AS HostName, SUSER_NAME() LoggedInUser
http://blog.sqlauthority.com/2009/05/26/sql-server-find-hostname-and-current-logged-in-user-name/
http://blog.sqlauthority.com/2009/05/26/sql-server-find-hostname-and-current-logged-in-user-name/
or
或者
SELECT @IP_Address = client_net_address
FROM sys.dm_exec_connections
WHERE Session_id = @@SPID;
How to get the client IP address from SQL Server 2008 itself?
如何从 SQL Server 2008 本身获取客户端 IP 地址?
How to identify the caller of a Stored Procedure from within the Sproc
回答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 作为安全功能。”