Przemyslaw Remin
Przemyslaw Remin

Reputation: 6940

SQL difference between host_name and hostname from sys.sysprocesses

What is the difference between these two queries:

select hostname,* from sys.sysprocesses where spid = @@SPID;
select host_name()

Likely the second one, requires less permission to user executing query.

Upvotes: 0

Views: 529

Answers (1)

sepupic
sepupic

Reputation: 8687

There is no difference from permissions point of view. Both queries can be executed having no permissions at all.

From sys.sysprocesses (Transact-SQL):

If a user has VIEW SERVER STATE permission on the server, the user will see all executing sessions in the instance of SQL Server; otherwise, the user will see only the current session.

In both cases the scope is current session only so there is no difference, and no permission is required.

Upvotes: 1

Related Questions