HOST_ID (Transact-SQL)
Applies to: SQL Server Azure SQL Managed Instance
Returns the workstation identification number. The workstation identification number is the process ID (PID) of the application on the client computer that is connecting to SQL Server.
Transact-SQL syntax conventions
Syntax
HOST_ID ()
Note
To view Transact-SQL syntax for SQL Server 2014 (12.x) and earlier versions, see Previous versions documentation.
Return Types
char(10)
Remarks
When the parameter to a system function is optional, the current database, host computer, server user, or database user is assumed. Built-in functions must always be followed by parentheses.
System functions can be used in the select list, in the WHERE clause, and anywhere an expression is allowed.
Examples
The following example creates a table that uses HOST_ID()
in a DEFAULT
definition to record the terminal ID of computers that insert rows into a table recording orders.
CREATE TABLE Orders
(OrderID INT PRIMARY KEY,
CustomerID NCHAR(5) REFERENCES Customers(CustomerID),
TerminalID CHAR(8) NOT NULL DEFAULT HOST_ID(),
OrderDate DATETIME NOT NULL,
ShipDate DATETIME NULL,
ShipperID INT NULL REFERENCES Shippers(ShipperID));
GO
See Also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for