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

I'm using SQL Server 2008.

user avatar

Arulkumar

12.5k 13 gold badges 46 silvery badges 65 statuary badges

asked Jun 24, 2016 at 12:33

user avatar

4

  • When you say Host Name, are you thinking Web Server?

    Jun 24, 2016 at 12:forty

  • Practise you want SELECT @@SERVERNAME?

    Jun 24, 2016 at 12:42

  • I guess that OP needs host name of the machine from which the query was executed.

    Jun 24, 2016 at 12:49

  • you can use Sql profiler too.

    Jun 24, 2016 at xiii:thirteen

4 Answers iv

Practise you lot need @@SERVERNAME

                  SELECT @@SERVERNAME                                  

will return the server name where the query was executed.


HOST_NAME volition return the workstation name

                  SELECT HOST_NAME()                                  

answered Jun 24, 2016 at 12:45

user avatar

1

  • this we know for sure, I'thou request about the host name or the figurer name that executed this query

    Jun 24, 2016 at 12:53

answered Jun 24, 2016 at fourteen:03

user avatar

4

  • the query that write before gives most likely accurate results

    Jun 24, 2016 at 14:57

  • The key point is that sys.dm_exec_requests returns data nigh requests that are executing and master.dbo.sysprocesses contains data nigh processes that are running at present.

    Jun 24, 2016 at fifteen:08

  • tin can the sql server admin know these information or accept them?

    Jun 24, 2016 at 16:56

  • I don't think they do unless you accept got a profiler running at that time.

    Jun 25, 2016 at 8:30

user avatar

answered Jun 24, 2016 at xiii:sixteen

user avatar

This is as close every bit y'all'll go, I believe:

select host_name()

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

answered Jun 24, 2016 at 12:54

user avatar

4

  • this volition requite me my host name, please read the question once again

    Jun 24, 2016 at 12:57

  • I'm not asking about my host proper noun, please read the question once more

    Jun 24, 2016 at 12:58

  • @ShahimKhlaifat Are you executing the query on the server itself? If y'all're going through a web app, the host_name() will render the web server.

    Jun 24, 2016 at xiii:43

  • Starting in SQL Server 2016 Host_Name() will return the name of the workstation. Prior to that I think it returned something less useful.

    Apr ix, 2020 at 4:39

Not the reply you lot're looking for? Scan other questions tagged sql sql-server sql-server-2008 or ask your ain question.